I am using following code to make a cross domain JSON request,
$.ajax({
type:"POST",
crossDomain:true,
contentType: "application/json; charset=utf-8",
data: {
domain: 'domain',
assettypes: 'Article',
sortby: 'mostreadcounter_total',
pagesize: '3',
format: 'json',
apikey: 'apiKey'
},
url: 'http://www.sample.com/search',
dataType: "json",
success: CallSucceed,
failure: CallFail,
beforeSend: function(x) {
if (x && x.overrideMimeType) {
x.overrideMimeType("application/json;charset=UTF-8");
}
}
});
But my call is failing. In fiddler I see the the content type as 'text/html; charset=UTF-8' while I am explicitly setting contentType as 'application/json;charset=UTF-8.'
When I access the API using browser, it works fine and Fiddler shows the proper content type. But as soon as I make the request using JQuery, my content type switches to text/html and my request fails with a 405 error (Method not allowed.)
This is happening only in Firefox 3.6 and not in IE :( I ahve tried both Get/POSt methods, I have tried adding and removing the code in "BeforeSend" but to no avail.
Any suggestions ?