Reputation: 26859
Using 1.7.2, I'm submitting a form using 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');
}
});
I was expecting the .ajax() call to set the XMLHTTPRequest header, but it isn't:
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
I've tried adding the headers
setting to the call, but it's not making any difference; the header isn't being set: "X-Requested-With":"XMLHttpRequest"
I've also tried
beforeSend: function (request) {
request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
}
Upvotes: 2
Views: 2419
Reputation: 731
Try this
$.ajax({
url: form.attr('action'),
dataType:'json',
type:'POST',
success:function(data){
console.log(data);
},
error:function(jxhr){
console.log(jxhr.responseText);
}
});
Upvotes: 1