简体   繁体   中英

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.

But the call of my function works just fine when I call it with only an 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):

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

You are using equals signs (=) instead of colons (:).

The data object should be like this instead:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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