0

Possible Duplicate:
Get URL parameter with jQuery

I have a form that posts data over ajax. The response comes back in the form of GET variables in the URL. For example if there was a failure of writing the form data the return address would be: http://example.com/?error=1

How would I check for this using jquery. Right now when I do a console.log on the msg variable I just get the html output of example.com (which I guess makes sense). I need the GET variables though. How would I achieve this?

$('#wp_email_capture').submit(function(e){
    var email = $('#wp-email-capture-email').val();
    $.ajax({
      type: "GET",
      url: "/",
      data: "wp_capture_action=1&wp-email-capture-email=" + email
    }).done(function( msg ) {
        console.log(msg)
    });
    e.preventDefault();
});
Community
  • 1
  • 1
greatwitenorth
  • 2,241
  • 2
  • 19
  • 21
  • Check this post: [how to get GET and POST variables with JQuery?][1] [1]: http://stackoverflow.com/questions/439463/how-to-get-get-and-post-variables-with-jquery – Nathan Mar 29 '12 at 22:09
  • Well I didn't end up finding a solution to this problem so I ended up outputting json from my php file instead. – greatwitenorth Mar 30 '12 at 15:24

1 Answers1

0

AJAX by default will return the content from the request. What you want are the headers.

If you are being given a return address of http://example.com?error=1, then it means this is being returned as a redirect header.

To get the header information from an AJAX request, that has been answered here: jQuery and AJAX response header

Community
  • 1
  • 1
cegfault
  • 6,442
  • 3
  • 27
  • 49
  • Just tried this out but it loks like the headers it reponds with do not contain the GET variables: Date: Thu, 29 Mar 2012 22:19:50 GMT Content-Encoding: gzip X-Powered-By: PHP/5.3.8 X-Pingback: http://example.com/xmlrpc.php Connection: close Pragma: no-cache Last-Modified: Thu, 29 Mar 2012 22:19:50 GMT Server: Apache/2.2.3 (CentOS) Vary: Accept-Encoding,Cookie,User-Agent Content-Type: text/html; charset=UTF-8 Cache-Control: no-cache, must-revalidate, max-age=0 Transfer-Encoding: chunked Expires: Wed, 11 Jan 1984 05:00:00 GMT – greatwitenorth Mar 29 '12 at 22:26