0

I am trying to ajax a form to a different domain using the jquery.xdomainajax.js plugin and having issue getting the desired HTML back (follow up to this question: Display form result in same page with only client-side script possible?)

The destination script checks the user id against the membership database, and redirects to an error page if the user has already submitted the form, or redirect to a thank you page if the entry is valid.

Using the script below, I get back the HTML of the ORIGINAL page on which the form is displayed, not the error page or the thank you page. If I change the dataType from "text" or "html" to "jsonp", I get a parse error as expected, but the associated HTML is actually desired HTML. I am not quite sure why.

Any help would be much appreciated!

PS: I do not have control over anything in the remote server.

$.ajax({
        type: settings.postType, //GET
        url: settings.tourl,
        data: aForm.serialize(),
        dataType: settings.type, //text or HTML
        crossDomain: true,
        success: function(data, textStatus, jqXHR){
            alert(data.responseText);
            settings.success(data);
        },
        error: function (jqXHR, textStatus, errorThrown){
            //alert(errorThrown);
            console.log(textStatus);                                                 
            settings.error();
        }

    });
Community
  • 1
  • 1
Alex N.
  • 173
  • 10

1 Answers1

0

Should your request type be a POST instead of a GET? Generally form info will be sent with a POST.

Ryan Nigro
  • 4,389
  • 2
  • 17
  • 23
  • Hi Ryan, thanks for the response. It seems I can't use POST without running into the cross-domain issue since I do not have control over the remote server code. I tried using GET with just the HTML (no ajax), and it seems to work correct so I was hoping GET would work with AJAX as well. – Alex N. Nov 25 '13 at 05:08
  • Makes sense re: cross domain permissions. What determines original vs. desired HTML on the page you're making the request to? Does it differ by a querystring parameter or something? – Ryan Nigro Nov 25 '13 at 05:10
  • I'm out for the night. Check out http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain. I think it'll answer your questions. Good luck! – Ryan Nigro Nov 25 '13 at 05:12