简体   繁体   English

内部使用 ajax 时未定义 Function 错误

[英]Function is not defined error when using ajax inside

I'm getting the error Uncaught ReferenceError: GetLicenceUserList is not defined in the browser console when I call the function using $.ajax function inside.当我使用$.ajax ZC1C425268E68385D1AB5074C17A9F4 调用 function 时,我收到错误Uncaught ReferenceError: GetLicenceUserList is not defined in the browser console。

But the call of my function works just fine when I call it with only an alert("example");但是我的 function 的调用工作得很好,当我只用一个alert("example"); inside.里面。

This are the code of both examples.这是两个示例的代码。

function GetLicenceUserList(id, actPage = 1, actualSearch = "", colOrder = 2, colDirec = "desc") {

alert(id + " - " + actPage + " - " + actualSearch + " - " + colOrder + " - " + colDirec);

/*$.ajax({
    url: "/Licences/UserLicenceList",
    type: "POST",
    data: {
        userId: id,
        actPage = actPage,
        actualSearch = actualSearch,
        colOrder = colOrder,
        colDirec = colDirec
    }
}).done(function (result) {
    $("#userLicence-list-card").html(result);
    alert("ok");
}).fail(function () {
    //operaciones en caso de falla
    alert("fail");
});*/
}

This one works great, and the following is where the error occurs (when uncomment the ajax call):这个效果很好,以下是发生错误的地方(取消注释 ajax 调用时):

function GetLicenceUserList(id, actPage = 1, actualSearch = "", colOrder = 2, colDirec = "desc") {

//alert(id + " - " + actPage + " - " + actualSearch + " - " + colOrder + " - " + colDirec);

$.ajax({
    url: "/Licences/UserLicenceList",
    type: "POST",
    data: {
        userId: id,
        actPage = actPage,
        actualSearch = actualSearch,
        colOrder = colOrder,
        colDirec = colDirec
    }
}).done(function (result) {
    $("#userLicence-list-card").html(result);
    alert("ok");
}).fail(function () {
    //operaciones en caso de falla
    alert("fail");
});
}

Your data object is not defined correctly in $ajax您的数据 object 未在 $ajax 中正确定义

You are using equals signs (=) instead of colons (:).您正在使用等号 (=) 而不是冒号 (:)。

The data object should be like this instead:数据 object 应该是这样的:

data: {
        userId: id,
        actPage: actPage,
        actualSearch: actualSearch,
        colOrder: colOrder,
        colDirec: colDirec
    }

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

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