var code = $.cookie('code');
$.ajax({
type: "POST",
url: "ajax/loadData.php",
data: { 'code': code },
dataType: "json",
success: function(data) {
console.log(data.coins);
},
error: function(emsg) {
alert(emsg.responseText);
}
});
基本上它显示了响应文本,并且在其中,它有:Notice: Undefined index: code in D:\wamp\www\ajax\loadData.php on line 3
并且我不确定为什么会这样,所以如果有人可以帮我清除它,我会感激不尽
loadData.php:
<?php
include '../inc/_db.php';
$code = $_POST['code'];
$query = mysqli_query($db, "SELECT * FROM data WHERE code='$code'");
$rows = array();
while($row = mysqli_fetch_array($query)) {
$rows[] = $row;
}
echo json_encode($rows);
?>
答案 0 :(得分:2)
尝试将数据参数设置为正确的json
$.ajax({
type: "POST",
url: "ajax/loadData.php",
data: { 'code': code },
dataType: "json",
success: function(data) {
console.log(data);
},
error: function(emsg) {
alert(emsg.responseText);
}
});
错误表明未设置$_POST['code']
,因此首先要查看的是您设置它的位置。