I am developing android app using jquery mobile. I have multiple pages in app. all the pages except index.html are database driven.
I want that id the particular link doesn't have any details in db then it shouldn't be directed to forward pages. i have made javascript function to check that but it doesn't works.
function check_category(b_id){
$.ajax({
url:'http://localhost/ajax_practice/php/get_categories.php?b_id='+b_id,
dataType: 'jsonp',
jsonp: 'jsoncallback',
timeout: 5000,
success:function(data,status){
if(data.success==0){
return false;
}else{
return true;
}
}
});
}
PHP CODE:
<?php
header('Content-type: application/json');
include 'connect.php';
$b_id=$_GET['b_id'];
$sql_select=mysql_query("SELECT * FROM businesses JOIN business_category ON business_category.b_id = businesses.id WHERE b_id=$b_id") or die(mysql_error());
$records = array();
if(mysql_num_rows($sql_select)>0){
while($row=mysql_fetch_array($sql_select)){
$records[] = $row;
}
//print_r($records);
echo $_GET['jsoncallback'] . '(' . json_encode($records) . ');';
}else{
$records= array(
'success'=>0,
);
echo $_GET['jsoncallback'] . '(' . json_encode($records) . ');';
}
?>
Basically what i want is if the data related to that business exit's in category table then it must return true otherwise false; so that href is no set to true or false.
Modify your script like this:
function check_category(b_id){
$.ajax({
url:'http://localhost/ajax_practice/php/get_categories.php?b_id='+b_id,
dataType: 'json',
timeout: 5000,
success:function(data,status){
if(data.success==0){
return false;
}else{
return true;
}
}
});
}
And edit your php too:
if(mysql_num_rows($sql_select)>0){
$records['success']=1;
while($row=mysql_fetch_array($sql_select)){
$records['data'][] = $row;
}
}else{
$records['success']=0;
}
echo json_encode($records);