我正面临一个问题,我的arr没有在第34行定义。我试图在互联网上找到解决方案,但没有任何问题。我的PHP没有问题。
错误如下:
未捕获的ReferenceError:未定义arr
$(document).on("pagebeforecreate", function () {
printheader();
});
$(document).ready(function () {
searchfriend();
function searchfriend() {
var url = serverURL() + "/getcategories.php";
$.ajax({
url: url,
type: 'GET',
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function (arr) {
_getCategoryResult(arr);
},
error: function () {
validationMsg();
}
});
}
function _getCategoryResult(arr) {
var t = $('#categoryresult').DataTable();
}
//loop for the number of results found by getcategories.php
for (var i = 0; i < arr.length; i++) { //error
//add a new row
t.row.add([
"<a href='#' class='ui-btn' id='btn" + arr[i].categoryID + "'>Category</a>" //add a new [Category] button
]).draw(false);
//We drew a [View] button. now bind it to some actions
$("#btn" + arr[i].categoryID).bind("click", { id: arr[i].categoryID }, function (event) {
var data = event.data;
showcategory(data.id); //when the user clicks on the [View] button, execute showcategory()
});
}
$("#categoryresult").show(); //show the results in the table searchresult
function showcategory(categoryID) {
//alert(categoryID);
window.location = "showlist.html?categoryID=" + categoryID;
}
});
答案 0 :(得分:0)
您的括号序列存在问题,
function _getCategoryResult(arr) {
var t = $('#categoryresult').DataTable();
//loop for the number of results found by getcategories.php
for (var i = 0; i < arr.length; i++) { //error
//add a new row
t.row.add([
"<a href='#' class='ui-btn' id='btn" + arr[i].categoryID + "'>Category</a>" //add a new [Category] button
]).draw(false);
//We drew a [View] button. now bind it to some actions
$("#btn" + arr[i].categoryID).bind("click", { id: arr[i].categoryID }, function (event) {
var data = event.data;
showcategory(data.id); //when the user clicks on the [View] button, execute showcategory()
});
}
$("#categoryresult").show(); //show the results in the table searchresult
};
function showcategory(categoryID) {
//alert(categoryID);
window.location = "showlist.html?categoryID=" + categoryID;
}