我正在尝试通过API登录服务器,但我遇到的问题是将'dataType'设置为JSON会导致我收到'No Response Body'。
当dataType为'json'时,我收到了这个:
Request URL: http://104.236.232.23/api/user/login/?Email=haye123%40gmail.com&Password=password&_=1438891065386
Request Method: GET
Status Code: HTTP/1.1 200 OK
Request Headers 13:06:42.000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0
Origin: null
Host: 104.236.232.23
Connection: keep-alive
Cache-Control: max-age=0
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Accept: */*
Sent Cookie
sessionid: 2w5vttprgffpb9q9mu395ko1lfz3hv54
csrftoken: NeEbmb3yKOpnb6IMLi5CCXKOYJwCe0ys
Response Headers Δ267ms
X-Frame-Options: SAMEORIGIN
Vary: Cookie
Server: nginx/1.4.6 (Ubuntu)
p3p: CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"
Date: Thu, 06 Aug 2015 20:06:43 GMT
Content-Type: application/json
Content-Length: 385
Connection: keep-alive
但是,如果我将dataType更改为'script',我会收到:
Request URL: http://104.236.232.23/api/user/login/?Email=haye123%40gmail.com&Password=password&_=1438891656317
Request Method: GET
Status Code: HTTP/1.1 200 OK
Request Headers 13:07:36.000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0
Host: 104.236.232.23
Connection: keep-alive
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Accept: */*
Sent Cookie
sessionid: 2w5vttprgffpb9q9mu395ko1lfz3hv54
csrftoken: NeEbmb3yKOpnb6IMLi5CCXKOYJwCe0ys
Response Headers Δ123ms
X-Frame-Options: SAMEORIGIN
Vary: Cookie
Server: nginx/1.4.6 (Ubuntu)
p3p: CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"
Date: Thu, 06 Aug 2015 20:07:37 GMT
Content-Type: application/json
Content-Length: 385
Connection: keep-alive
Response Body Δ0ms
{"last_name": "Name", "profile_image": "https://", "background_image": "", "is_staff": true, "id": 99, "date_joined": "01/09/2015", "first_name": "Aaron", "about_text": "", "gender": "", "age": null, "company_name": "0", "is_pro": false, "email": "email@gmail.com", "website_url": ""}
当json设置为dataType时,什么可能导致Response体不显示?
以下是有问题的代码:
function Login2() {
if( xhr != null ) {
xhr.abort();
xhr = null;
}
ajax_url = "http://104.236.232.23/api/user/login/";
ajax_type = "GET";
ajax_data = {'Email' : "email@gmail.com", 'Password' : "password" };
xhr = $.ajax({
url: ajax_url,
type: ajax_type,
data: ajax_data,
crossDomain: true,
dataType: 'json',
xhrFields: {
withCredentials: true
},
headers: {
'Accept': '*/*'
},
success: function(data, textStatus, XMLHttpRequest){
alert("boom");
var cookietoSet=XMLHttpRequest.getResponseHeader('Set-Cookie');
Set_Cookie(cookietoSet.split('=')[0],cookietoSet.split('=')[1],expires, path, domain, secure) //change as per ur needs
}, //close success
error: function( jqXHR, textStatus ){
alert( "Request failed: " + textStatus );
}
});
} //end function