[英]Getting error in jquery ajax “function not defined”
我从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后发布了这个问题。
谢谢
我认为这里的问题是你将一个匿名函数传递给get_CommentCount。 尝试使用正常功能,它应该更好。
在你的ajax的成功函数中你已经编写了句柄(数据),它是一个你没有写过任何可能的函数,所以这个错误告诉你TypeError: handleData is not a function
所以你已经定义了一个像
function handleData(data)
{
alert(data);
}
这对你有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.