jqueryajax类型:';获取';用PHP出问题
直到今天早上,我一直试图从Mysql和ajax检索数据 这是我的代码: HTML:jqueryajax类型:';获取';用PHP出问题,php,jquery,ajax,Php,Jquery,Ajax,直到今天早上,我一直试图从Mysql和ajax检索数据 这是我的代码: HTML: $.ajax({ //type:'GET', url: "/lecture_message_pilote.php", data: ({location_id:zlid}), contentType: "application/json; charset=utf-8", dataType: 'json', //data format success:
$.ajax({
//type:'GET',
url: "/lecture_message_pilote.php",
data: ({location_id:zlid}),
contentType: "application/json; charset=utf-8",
dataType: 'json', //data format
success: function(data) //on recieve of reply
{
var zidpilote = data[0]; //get id
var zmessage = data[1]; //get name
alert(zmessage);
}
});
和PHP:
$result = mysql_query("select * from Test_phoneGAP_message where IDPILOTE = '".$location_id."'");
$array = mysql_fetch_row($result);
echo (json_encode($array));
mysql_close();
我收到了错误消息:未定义警报(zmessage);
如果我使用PHP请求:
$result = mysql_query("select * from Test_phoneGAP_message");
我有一个好结果。我认为我的PHP没有使用
$location\u id
尝试通过PHP的$\u REQUEST[“location\u id”]元素访问参数
i、 e
请改用
mysqli
或PDO。最好不要使用$\u REQUEST
和$\u GET
或$\u POST
。@user2078935如果有效,那么您必须接受它作为答案。
$result = mysql_query("select * from Test_phoneGAP_message where IDPILOTE = '".$_REQUEST["location_id"]."'"); $array = mysql_fetch_row($result);