我从jquery ajax返回一些值。我得到了结果,但是与此同时我也得到了一个错误。首先请看一下代码
function get_CommentCount(handleData) {
$.ajax({
url: 'Profile/get_CommentCount',
type: "post",
dataType: 'json',
success: function(data) {
handleData(data);
}
});
}
像这样调用此函数
get_CommentCount(function(output) {
console.log('output', output)
});
它给我
TypeError: handleData is not a function
错误。请任何人告诉我为什么我会收到此错误。我已经解决了stackoverflow问题,但找不到任何解决方案。可能是您发现它重复,但是我在浏览stackoverflow之后发布了此问题。谢谢
最佳答案
在ajax的成功函数中,您已经编写了handle(data),并且您没有在任何地方编写该函数,因此此错误向您显示TypeError: handleData is not a function
,因此您已定义了以下函数
function handleData(data)
{
alert(data);
}
这将为您工作。
关于javascript - 在jQuery Ajax“未定义函数”中出现错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37784184/