gpt4 book ai didi

javascript - Uncaught ReferenceError : arr is not defined

转载 作者:行者123 更新时间:2023-11-28 03:43:50 28 4
gpt4 key购买 nike

我面临一个问题,即我的 arr 未在第 34 行定义。我试图在互联网上找到解决方案,但没有任何解决方案。我的 PHP 没有任何问题。

错误如下:

Uncaught ReferenceError: arr is not defined

$(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;

}
});

最佳答案

您对括号序列有疑问,

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;
}

关于javascript - Uncaught ReferenceError : arr is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48678887/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com