2012-04-27 44 views
1

使用1.7.2,我提交使用jQuery.ajax()形式:)jQuery.ajax不發送一個XMLHttpRequest頭

jQuery.ajax({ 
    url: form.attr('action'), 
    action: 'POST', 
    dataType: 'json', 
    data: {post_id: id}, 
    success: function(data) { 
     console.log('hurrah!'); 
    }, 
    error: function() { 
     console.log('whoops'); 
    } 
}); 

我期待的阿賈克斯(呼叫設置了XMLHttpRequest頭,但它不是:

Referer: http://0.0.0.0:5000/messages/news-feed 
Origin: http://0.0.0.0:5000 
Content-Length: 42 
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.18.5 (KHTML, like Gecko) Version/5.2 Safari/535.18.5 
Connection: keep-alive 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-us 
Content-Type: application/x-www-form-urlencoded 
Accept-Encoding: gzip, deflate 

我試着加入headers設置的號召,但它沒有做任何區別;頭沒有被設置:"X-Requested-With":"XMLHttpRequest"

我也試過

beforeSend: function (request) { 
    request.setRequestHeader("X-Requested-With", "XMLHttpRequest"); 
} 
+0

那......是怪異。 – MacMac 2012-04-27 11:05:12

+0

'form.attr('action')'與表單放置的頁面具有相同的http地址和端口嗎? – 2012-04-27 11:54:16

回答

1

試試這個

$.ajax({ 
url: form.attr('action'), 
dataType:'json', 
type:'POST', 
success:function(data){ 
console.log(data); 
}, 
error:function(jxhr){ 
console.log(jxhr.responseText); 
} 

}); 
+0

我沒有收到錯誤,所以沒有jxhr對象。 – urschrei 2012-04-27 11:16:33

+0

[點擊這裏](http://forums.codeguru.com/showthread.php?t=474951)知道...我只是給你演示相應的你可以修改它 – harry 2012-04-27 11:24:25

相關問題