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