I’m facing the same issue, while trying for cross-domain request. Situation is strange, my data is getting loaded while hit the requested url directly on browser, the strange part is, this gets loaded if requested using jquery ajax as well,
but not on firebug console, but on firebug net tab.
Console prints:
Sample of error data: parsererror {while json data is well-formed and formatted, checked on json validators}
readyState: 4 status: 200 responseText: undefined
Net tab loads all the data in response and json sub-tab
My sample code is:
function fetchJsonData() {
$.ajax({
type: 'POST',
url: 'http://www.meilleurmobile.com/comparateur/resultats-comparateur-json.do',
data: 'monthDur%5B0%5D=45.75&monthDur%5B1%5D=45.75&monthDur%5B2%5D=45.75&monthDur%5B3%5D=45.75&monthDur%5B4%5D=45.75&monthDur%5B5%5D=45.75&monthDur%5B6%5D=45.75&monthDur%5B7%5D=45.75&monthDur%5B8%5D=45.75&monthDur%5B9%5D=45.75&monthDur%5B10%5D=45.75&monthDur%5B11%5D=45.75&numSms=1000&dataVolume=1000&withoutMobile=-1&commitmentDuration=-1',
async: false,
cache: false,
//contentType: 'application/json; charset=utf-8',
crossDomain: true,
dataType: 'jsonp',
error: function( xhr,err ) {
console.log( 'Sample of error data:', err );
console.log("readyState: "+xhr.readyState+"\nstatus: "+xhr.status+"\nresponseText: "+xhr.responseText);
},
success: function( data ) {
if (console && console.log) {
console.log( 'Sample of data:', data.slice(0,100) );
}
}
})
.done(function() { alert("success"); })
.fail(function() { alert("error"); });
}
Attempted cross domain XMLHttpRequest requests may fool you. In Firefox web console, it may look like URL loaded fine, but body is an empty string.
Confirm that the server supports JsonP. If you don’t really know what that means, you need to look it up. It is critically important.
jQuery assumes that the JsonP parameter is going to be “?callback=”. If that is not true, you should see this: http://api.jquery.com/jQuery.ajax/
If it gets confusing, it may be easier to just do it the old fashioned way and appends the script to the page yourself with a time stamp in the URL to avoid using a cached script page.
BTW, AFAIK, there is no way to combine JSONP and POST. JSONP is a way of working around the same origin security policy of XMLHttpRequest. It requires you to append a script to the DOM. I don’t think you can do that and also submit POST variables as part of the process.