我将它从 php 编码回这个 js 文件,并且我得到了不能使用“in”运算符进行搜索的信息。我 window.alert(data) 它看起来是正确的。
未捕获的类型错误:无法使用 'in' 运算符在 {"0":{"Name":"Duncan Davis","0":"Duncan Davis","Type":"Student"中搜索 '728' ,"1":"学生"},"1":{"姓名":"安德鲁·麦基","0":"安德鲁·麦基","类型":"教授","1":"教授"}, "2":{"姓名":"乔·史密斯","0":"乔·史密斯","类型":"学生","1":"学生"},"3":{"姓名":"约翰·海塔尔","0":"约翰·海塔尔","类型":"教授","1":"教授"},"4":{"姓名":"猫收藏家","0":"猫收集者","类型":"组","1":"组"},"5":{"名称":"数据库知识","0":"数据库知识","类型":"组","1":"组"},"6":{"名称":"词典","0":"词典","类型":"图书","1":"图书"},"7 ":{"Name":"猫词典","0":"猫词典","Type":"书","1":"书"},"8":{"Name":"土 bean 字典","0":"土 bean 字典","类型":"书","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>');
});
}
});
最佳答案
$.ajax({
url: '../php/DBConnect.php',
type: 'POST',
data: Input,
success: DataReturn,
error: function (xhr, status, err) { }
});
添加数据类型:'json'
$.ajax({
url: '../php/DBConnect.php',
type: 'POST',
data: Input,
dataType: 'json',
success: DataReturn,
error: function (xhr, status, err) { }
});
关于javascript - 无法使用 'in' 运算符在中搜索 '728',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25695958/