First of all love this resource - been using it and learning for a couple years now. This is my first post as I am truly stuck. I am submitting a form via ajax /jsonp. If I run this script locally - I get a response back from the domain with a success code. If I just run the request in the browser it gives me response back with success code. But when I submit my form - Firebug gives my a 200 OK in RED with no response from the server. Safari gives me a failed to load resource: cancelled. Cant find much documentation on the errors so I have come to a 开发者_如何转开发halt. I know this is probably terribly disgusting for u pros to read but this is my first post so any guidance is appreciated! There are two examples online: http://www.yourlifeportal.com/register.php which has is the version with reCaptcha. http://www.yourlifeportal.com/registerNew.php has no reCaptcha just incase the addition of the captcha affected my code. If I just need a smack in the face let me know that too. Thank you!
$.ajax({
url: 'http://myURLonaDifferentDomain',
data:jQuery(frm).serialize(),
type: 'POST',
dataType: 'jsonp',
jsonp: 'jsonp',
crossDomain: true,
error: function (xmlHttpRequest, textStatus, errorThrown) {
if(xmlHttpRequest.readyState == 0 || xmlHttpRequest.status == 0)
return; // it's not really an error
else
alert(xmlHttpRequest + ': ' + textStatus + ': ' + errorThrown);
},
success: function(jsonp) {
// Response handling code goes here
console.log(json.response.responseCode + ': ' + json.response.response + ': ' + json.response.responseDescription);
if (json.response.responseCode == 10527) {
document.getElementById('errorScreen').style.display='block';
$('#errorMsg').append('There was an error with your credit card transaction please go back and re-check your ');
}
if (json.response.responseDescription == "Registration was successful") {
window.location.replace("http://www.url.com/thankyou.php");
}
}
});
}
Hahaha. Cross-domain scripting. It's a big problem. Read about the solution here.
EDIT I re-read the question and noticed that you already had the AJAX ready for cross-domain (although it usually notices by itself); the problem is almost certainly that you don't have the remote Web server ready. Use Firebug, open the Net tab, and look at the Response headers for the characteristic CORS headers.
I had a similar issue and the solution was that JSONP responses have to wrapped in a callback function. Answer here: https://stackoverflow.com/a/10892749/498903
精彩评论