Ajax成功无法启动

jas*_*328 1 javascript ajax jquery

我有一个简单的ajax帖子到服务器..

$(".invite-team-members-submit-btn").click(function() {
  $.post("invite_team_member", { token: $("#token").val(), email: $("#email").val(), team: $("#team").val() })
    .done(function (responseText) {
      responseText = jQuery.parseJSON(responseText);
      alert(responseText.response);
    })
    .fail(function (data) { alert("ERROR: " + data); })
    .then(function () { alert("Something should happen."); });
});
Run Code Online (Sandbox Code Playgroud)

返回的JSON看起来像这样......

{"response":"Person has been invited."}
Run Code Online (Sandbox Code Playgroud)

我在控制台中的响应标题看起来像这样......

Response Headers
  Cache-Control max-age=0, private, must-revalidate
  Connection    close
  Content-Type  application/json; charset=utf-8
  Date  Wed, 22 May 2013 21:45:07 GMT
  Etag  "e5b5e12acbcc78372b2a861027b66c05"
  Status    200 OK
  Transfer-Encoding chunked
  X-Request-Id  d835ce021eff7733d67ebfcdd468bdf2
  X-Runtime 0.007909
  x-ua-compatible   IE=Edge
Run Code Online (Sandbox Code Playgroud)

在我的控制台中,我看到它是服务器并返回了相应的文本,但我的浏览器中没有收到警报.我只是出于对错误的想法.jQuery是否更新了我缺少的东西?

Exp*_*lls 6

您使用$.post不当.您的意思是使用$.ajax并指定type: "post"属性.

$.post第一个参数是URL.在你的情况下,它是一个对象.我认为也许jQuery最终会使用当前页面URL来发出请求(这就是为什么你会看到),但我不能确定.您可以将其重写为:

$.post("invite_team_member", {data: data})
    .done(function (responseText) { alert(responseText); })
    .fail(function (data) { alert("ERROR: " + data); });
Run Code Online (Sandbox Code Playgroud)