为什么在HTTP 200响应上调用$ .ajax错误处理程序?

时间:2015-04-08 22:40:07

标签: javascript jquery ajax

尽管收到200响应,但此代码总是在错误处理程序中结束。使用curl,这是来自服务器的响应。请注意,我明确指定了html的dataType。

  

使用jQuery 1.11.2

$.ajax({
        url: "/sendmail?to=" + mailto + "&subject=" + subject + "&body=" + body,
        method: 'POST',
        dataType: 'html'

      })
      .done(function(data, textStatus, jqXHR) {
        console.log('Mail sent to ' + mailto);
      })
      .fail(function(jqXHR, textStatus, errorThrown) {
        console.log('Failed to send mail to ' + mailto);
      });
curl -v --data "to=multi4@tim.com&subject=Your%20account&body=%3Cp%3EHi,%20Tim" http://localhost:9000/sendmail
* Adding handle: conn: 0x7fd1c8803000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fd1c8803000) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 9000 (#0)
*   Trying ::1...
* Connected to localhost (::1) port 9000 (#0)
> POST /sendmail HTTP/1.1
> User-Agent: curl/7.30.0
> Host: localhost:9000
> Accept: */*
> Content-Length: 397
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 397 out of 397 bytes
< HTTP/1.1 200 OK
< content-type: text/html; charset=utf-8
< cache-control: no-cache
< Content-Length: 0
* Server Development/2.0 is not blacklisted
< Server: Development/2.0
< Date: Wed, 08 Apr 2015 22:21:50 GMT
< 
* Connection #0 to host localhost left intact

0 个答案:

没有答案