简体   繁体   中英

ajax jsonp request - no response

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");             
            } 

        }
                        });


}

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM