jquery ajax完成功能没有触发

我有一个非常简单的jQuery Ajax调用(下)。 Ajax调用执行,我可以在Firebug Net面板中看到服务器返回200 OK,并返回一个字符串“OK”,因为它应该。但是,完成和失败的功能不会触发!非常沮丧!

(“之前”和“之后”警告都会触发。)

为了简单起见(作为一种调试技术),我把它剥离下来,它是最裸的骨架,但是处理程序仍然不会触发。我在这里看不到什么

postUrl= "/mod/users/check_email/";
dataToPost= { email: "test@not.me" };

alert("before");
$.ajax
({
    type: "POST",url: postUrl,data: dataToPost,done: function() 
    {
        alert("Success.");
    },fail: function() 
    {
        alert("Sorry. Server unavailable. ");
    },});  // end Ajax call 

alert("after");

解决方法

您需要链接done()和fail()函数,它们不是$ .ajax中使用的选项对象的一部分:
$.ajax({
    type: "POST",url : postUrl,data: dataToPost
}).done(function()  {
    alert("Success.");
}).fail(function()  {
    alert("Sorry. Server unavailable. ");
});

另外,由于ajax是异步的,如果“after”警报到达“成功”警报之前,不要惊讶。

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...