我正在開發使用jquery mobile的android應用程序。我在應用程序中有多個頁面。除index.html之外的所有頁面都是由數據庫驅動的。檢查值,然後指向不同的頁面
我想這個ID的特定鏈接沒有任何細節在分貝然後它不應該被定向到轉發頁面。我已經使javascript功能來檢查,但它不起作用。
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代碼:
<?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) . ');';
}
?>
基本上我想要的是如果類別表與該企業出口的數據,那麼它必須返回true,否則爲false;這樣href就不會被設置爲true或false。
*旁註:*停止使用廢棄的'mysql_ *'功能。改用MySQLi或PDO。 – Raptor