jQuery $ .ajax完成回调未触发 [英] jQuery $.ajax done callback not firing

查看:143
本文介绍了jQuery $ .ajax完成回调未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

$("#loginSubmitButton").on("click",function(){
  var loginUserDetails = {
    email: $("#email").val(),
    password: $("#password").val()
  };

  //Send the AJAX request to authenticate the user
  $.ajax({
    type: "POST",
    url: "/somewebservice/v1/users/authenticate",
    data: JSON.stringify(loginUserDetails),
    contentType: "application/json;charset=UTF-8",
    dataType: "json",
  }).done(function() {
      $("#loginResult").text("Login successful");
    })
    .fail(function() {
      $("#loginResult").text("Login failed");
    });

});

根据jquery文档(除非我理解错误)我希望完成我从我的网络服务器收到200 OK。但是,在chrome控制台中我可以看到200 OK响应,但jquery似乎触发了失败处理程序。

As per the jquery documentation (unless I am understanding something incorrectly) I expect the done to be fired if I receive a 200 OK from my web server. However, in chrome console I can see a 200 OK response but jquery seems to fire the fail handler.

有谁知道我在这里做错了什么?

Does anyone have any idea what I might be doing wrong here?

推荐答案

您需要删除:

dataType:json

这篇关于jQuery $ .ajax完成回调未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆