php返回json数据的demo如下,请问是什么原因导致该问题?
程序员文章站
2022-05-10 18:37:55
...
query("select id from user2 where name = 'admin' and password ='admin'");
//$user_details = $db->get_row(null, OBJECT, 0);
//var_dump($user_details) ;
$sql = sprintf("select * from user2 where name='%s' and password='%s'",$username,$password);
//echo $sql;
//select * from user2 where name='admin' and password='admin'
$user=$db->get_results($sql);
//var_dump($user);
//array(1) { [0]=> object(stdClass)#5 (3) { ["id"]=> string(1) "1" ["name"]=> string(5) "admin" ["password"]=> string(5) "admin" } }
if($user){
$result='0';
}else{
$result='-1';
}
$arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);
echo json_encode($arr);
?>
php返回json数据,若含有
$user=$db->get_results($sql);
这行代码ajax就返回error。
若去掉这行代码,则ajax结果是success
html代码如下:
英方I2Active