未捕获的类型错误:回调不是函数 [英] Uncaught TypeError: callback is not a function

查看:35
本文介绍了未捕获的类型错误:回调不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能:

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

这个函数被另一个像这样的ajax操作调用:

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

我需要在ajax操作后返回值到函数定义的区域.但是这里我有一个错误

I need return value to function defined area after ajax operation. But here I got a error

Uncaught TypeError: callback is not a function

推荐答案

检查其余代码以调用 reportMemberList 并确保始终使用回调作为参数调用它.如果您在任何地方省略回调参数(例如,仅使用 projectId 参数调用 reportMemberList),上面的代码将正确解析对具有回调的函数的其他调用将产生错误.(这就是我的解决方案.)

Check the rest of your code for calls to reportMemberList and make sure you always call it with the callback as a parameter. If you omit the callback parameter anywhere (e.g. call reportMemberList with just the projectId parameter), the code above would parse correctly the other calls to the function with the callback would produce the error. (This was the solution for me.)

这篇关于未捕获的类型错误:回调不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆