我是json编码它从php返回到这个js文件,我得到不能使用'in‘操作符搜索。I window.alert(数据),它看起来是正确的。
Uncaught :不能使用' in‘运算符搜索'728’在{“0”:{“名称”:“邓肯戴维斯”,“0”:“邓肯戴维斯”,“类型”:“学生”,“1”:“学生”},“1”:“1”:{“名称”:“安德鲁·麦基”,“0”:“安德鲁·麦基”,“类型”:“教授”,“1”:“教授”},“2”:{“名称”:“乔·史密斯”,“0”:“乔·史密斯”,“类型”:“学生”,“1”:“学生”},“3”:{“名称”:“约翰·海塔”,“0”:“约翰·海塔”,“类型”:“教授”,“1”:“教授”},“4”:{“名称”:“猫收藏者”,“0”:“猫收藏者”,“0”:“猫收藏者”,“类型”:“组”,“1”:“组”},“5”:{“名称”:“数据库知识”,“0”:“数据库知识”,“类型”:“组”、“1”:“组”}、“6”:{“名称”:“字典”、“0”:“字典”、“类型”:“图书”、“1”、“7”:{“名称”:“猫词典”、“0”:“猫词典”、“类型”、“1”、“图书”}、“8”:“名称”:“土豆词典”,“0”:“土豆词典”,“类型”:“图书”,“1”:“图书”}
$(function () {
$("#login_form").on('submit', function () {
var Input = document.test.Input.value;
window.alert(Input);
// use ajax to run the check
$.ajax({
url: '../php/DBConnect.php',
type: 'POST',
data: Input,
success: DataReturn,
error: function (xhr, status, err) { }
});
return false;
});
function DataReturn(Data) {
window.alert(Data);
var tableheader = "<thead><tr><th>Name</th><th>Type</th></tr></thead>";
$('#table').empty();
$('#table').append(tableheader);
$.each(Data, function (index, item) {
$('#table').append('<tr><td>'
+ item['Name']
+ '</td><td>'
+ item['Type']
+ '</td></tr>');
});
}});
发布于 2014-09-06 02:12:33
$.ajax({
url: '../php/DBConnect.php',
type: 'POST',
data: Input,
success: DataReturn,
error: function (xhr, status, err) { }
});添加dataType: 'json'
$.ajax({
url: '../php/DBConnect.php',
type: 'POST',
data: Input,
dataType: 'json',
success: DataReturn,
error: function (xhr, status, err) { }
});https://stackoverflow.com/questions/25695958
复制相似问题