JavaScript调用PHP WebService

i just try to use javascript for build mobile apps. This apps required connection to sql server. I already create the javascript and php file, but whenever i try to call the function it gave me no results. this is the javascript function:

function getvoucher()
{

    var result = jQuery.ajax({
    type: "GET",
    url: aurl,
    data: "tag=getvoucher"
    async: false
    }).responseText;
    if(result)
    {
     var obj = jQuery.parseJSON(result);
     if(obj.success == 1)
     {
             var voucher=obj.name;
             document.write(voucher);
     }
    }
}

this is my phpscript:

<?php
include("../includes/config.php");

if(isset($_REQUEST['tag']) && ($_REQUEST['tag']=='getvoucher'))
{
$success=0;
$query=mysql_query("select code from tbl_voucher")or die ("query issue");
#if(mysql_num_rows($query) > 0)
#        {
             if($query)
                {

                        $success=1;
                        $code=$row['code'];
                 }


#        }

$jsondata = array('tag'=>"getvoucher",'success'=>$success, 'code'=>$code);
echo json_encode($jsondata);
if($query){mysql_free_result($query);}
mysql_close($con);
die;
}
>?

The php and connection to sql is working because i already success in other script. And the tbl_voucher and column code is already exist.

Thanks

Perhaps the last die in your php script might be messing up. Loose it.

$jsondata = array( 'tag '=> 'getvoucher','success' => $success, 'code' => $code);
echo json_encode( $jsondata );
if( $query ){ mysql_free_result( $query ); }
mysql_close( $con );
die;

By the way, you are missing a coma here

data: "tag=getvoucher"

Also, your ajax call seems bit weired.

var result = jQuery.ajax({
    type: "GET",
    url: aurl,
    data: "tag=getvoucher"
    async: false
}).responseText;
if ( result )
{
    var obj = jQuery.parseJSON( result );
    if(obj.success == 1)
    {
        var voucher=obj.name;
        document.write( voucher );
    }
}

Instead, try this

$.ajax({

    type: "GET",
    url: aurl,
    data: "tag=getvoucher",
    async: false,
    success: function( object ) {
        document.write( object.name );
    }

});

If you use google chrome and run the webpage/script, press F12 and look at network=>XHR. Then you can look at what is submitted and you can even open the result-page.

This way you can see if your parameters are passed and you can see what gets returned. If something is not passed, you need to fix it on the sender side. If it is sent and return data is sent, it means reciever side is wrong :-)