Laz*_*man 3 javascript ajax jquery 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"); });
Run Code Online (Sandbox Code Playgroud)
我收到警报("获取...")对话框,但其余代码未完成.我收到错误:错误:$ .post("sec_fetch_report.php",function(){alert("fetching ...");}).success不是函数
我想也许我可能会错过jquery libs,但我有另一个调用$ .post的函数,它运行得很好.是否存在语法错误,我在某处丢失或者什么?谢谢
你的语法坏了.你要做的是调用$ .post()方法的.success属性,这显然不存在.看起来您还需要使用该$.ajax
方法而不是$.post
:
$.ajax({
type: 'POST',
url: 'mypage.php',
data: { url: pageurl },
beforeSend: function()
{
alert('Fetching....');
},
success: function()
{
alert('Fetch Complete');
},
error: function()
{
alert('Error');
},
complete: function()
{
alert('Complete')
}
});
Run Code Online (Sandbox Code Playgroud)