在1.7.2中,我使用jQuery.ajax()提交了一个表单:
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');
}
});我期望.ajax()调用来设置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");
}发布于 2012-04-27 19:10:43
尝尝这个
$.ajax({
url: form.attr('action'),
dataType:'json',
type:'POST',
success:function(data){
console.log(data);
},
error:function(jxhr){
console.log(jxhr.responseText);
}
}); https://stackoverflow.com/questions/10349445
复制相似问题