$.post 失败并出现错误“...不是函数”
这是我的代码:
var jqxhr = $.post("mypage.php", {url:pageurl}, function() {
alert("fetching...");
})
.success(function() { alert("fetch complete!"); })
.error(function() { alert("error!"); })
.complete(function() { alert("complete"); });
// Set another completion function for the request above
jqxhr.complete(function(){ alert("second complete"); });
我收到警报(“正在获取...”)对话框,但其余代码未完成。我收到错误: Error: $.post("sec_fetch_report.php", function () {alert("fetching...");}).success 不是一个函数
我想我可能会丢失 jquery 库,但我有另一个调用 $.post 的函数,它运行得很好。我在某处遗漏了语法错误还是什么? 谢谢
Here is my code:
var jqxhr = $.post("mypage.php", {url:pageurl}, function() {
alert("fetching...");
})
.success(function() { alert("fetch complete!"); })
.error(function() { alert("error!"); })
.complete(function() { alert("complete"); });
// Set another completion function for the request above
jqxhr.complete(function(){ alert("second complete"); });
I get the alert("Fetching...") dialog box, but the rest of the code does not complete. I get the error: Error: $.post("sec_fetch_report.php", function () {alert("fetching...");}).success is not a function
I thought maybe I might be missing the jquery libs, but I have another function that calls $.post and it runs just fine. Is there a syntax error I'm missing somewhere or what?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你的语法被破坏了。您尝试做的是调用 $.post() 方法的 .success 属性,该属性显然不存在。看起来您还需要使用
$.ajax
方法而不是$.post
:Your syntax is broken. What you're attempting to do is call the .success property of the $.post() method, which obviously doesnt exist. It looks like you also need to be using the
$.ajax
method instead of$.post
:该语法仅在 jQuery 1.5+ 中受支持(引入了延迟)。听起来您使用的是早期版本的 jQuery。如果您无法升级,请将成功/错误/完成处理程序作为选项对象的方法传递(如 Tejs 的示例)。
That syntax is only supported in jQuery 1.5+ (with the introduction of deferreds). It sounds like you're using a earlier version of jQuery. If you aren't able to upgrade, pass the success/error/complete handlers as methods of the options object (like in Tejs's example).
jqxhr 对象从 v1.5 开始可链接。确保您有此版本或更高版本。
参考:jQuery 1.5 发布,现在带有延迟对象
The jqxhr object is chainable from v1.5. Make sure you have this version or later.
Ref: jQuery 1.5 released, now with Deferred Objects
请参阅此处的示例: jQuery.post
另外,如果您忘记了,您可能会收到类似的错误链接 jQuery 库
See examples here: jQuery.post
also, you may get error like that if you've forgotten to link jQuery library
参考: https://api.jquery.com/jQuery.post/
Ref: https://api.jquery.com/jQuery.post/