admin管理员组文章数量:1406308
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 return value to function defined area after ajax operation. But here I got a error
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 return value to function defined area after ajax operation. But here I got a error
Uncaught TypeError: callback is not a function
Share
Improve this question
edited May 7, 2015 at 11:02
Regent
5,1763 gold badges23 silver badges35 bronze badges
asked May 7, 2015 at 10:58
jagadeesh puthukkudijagadeesh puthukkudi
931 gold badge1 silver badge8 bronze badges
4
-
I am not sure but i doubt it is because of your
JSONP
– Vigneswaran Marimuthu Commented May 7, 2015 at 11:15 - Bad luck. It is not working when i removed JSONP. – jagadeesh puthukkudi Commented May 7, 2015 at 11:18
- could you please post the sample of your server response? – smnbbrv Commented May 7, 2015 at 11:20
- It is JSON Response [{"timesheet_user_id":"5","timesheet_hours":"4","name":"jagadeesh puthukkudi"},{"timesheet_user_id":"8","timesheet_hours":"7","name":"admin admin"},{"timesheet_user_id":"5","timesheet_hours":"2","name":"jagadeesh puthukkudi"}] – jagadeesh puthukkudi Commented May 7, 2015 at 11:32
2 Answers
Reset to default 1Check 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.)
guessing, but try to change your "jsonp" to "json". If you don't make cross-origin requests there, it should work
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);
});
}
本文标签: javascriptUncaught TypeError callback is not a functionStack Overflow
版权声明:本文标题:javascript - Uncaught TypeError: callback is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745006104a2637271.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论