简体   繁体   English

未捕获的ReferenceError:未定义arr

[英]Uncaught ReferenceError: arr is not defined

I am facing a problem whereby my arr is not defined at line 34. I tried to find solution on the internet but there wasn't any. 我遇到一个问题,即在第34行中未定义我的arr。我试图在Internet上找到解决方案,但没有任何解决方案。 There are no problems with my PHP. 我的PHP没有任何问题。

The error is as follows: 错误如下:

Uncaught ReferenceError: arr is not defined 未捕获的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;

}
});

You have issue with bracket sequence, 您对括号顺序有疑问,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM