Uncaught TypeError: callback is not a function

I have a function:

reportAdminActions.reportMemberList(project, function(data) {
    console.log(data);
}); 

This function is called by another ajax operation like these:

reportMemberList: function(projectId, callback) {
    var projectDetail = new Object();
    projectDetail.projectId = projectId;
    var pluginArrayProject = new Array();
    pluginArrayProject.push(projectDetail);   
    $.ajax({
        url : ConfigCom.serverUrl + 'projectreportonmember',
        dataType: "jsonp",
        type: "POST",
        data: JSON.stringify(pluginArrayProject)
    }).always(function(data) {
        callback(data.responseText);
    });
}

I need to return a value for a function given a scope after an ajax operation. But here I got an error

Uncaught TypeError: callback is not a function
+4
source share
2 answers

Check the rest of the code for calls reportMemberListand make sure you always call it with a callback as a parameter. If you omit the callback parameter anywhere (for example, calling reportMemberListonly with the parameter projectId), the above code will correctly analyze other calls to the function with the callback, which will lead to an error. (This was a decision for me.)

+1
source

, "jsonp" "json". -,

reportMemberList: function(projectId, callback) {
    var projectDetail = new Object();
    projectDetail.projectId = projectId;
    var pluginArrayProject = new Array();
    pluginArrayProject.push(projectDetail);   
    $.ajax({
        url : ConfigCom.serverUrl + 'projectreportonmember',
        dataType: "json",
        type: "POST",
        data: JSON.stringify(pluginArrayProject)
    }).always(function(data) {
        callback(data.responseText);
    });
}
0

All Articles