Forum Moderators: open

Message Too Old, No Replies

Jquery Ajax GET Problem!

         

lobas

6:02 pm on Sep 30, 2010 (gmt 0)

10+ Year Member



Your help would be most appreciated. I'm dong this jquery ajax GET right. Although it submits and sends as a $_GET and is processed fine by process.php for some reason it is not reflected in the url.


jQuery('#results-submit').click(function() {

jQuery('#waiting').show(0);
jQuery('#container').hide(0);
jQuery('div.carpark').remove();

jQuery.ajax({
type : 'GET',
url : 'process.php',
dataType : 'json',
data: {
airport : jQuery('#airport').val(),
name : jQuery('#name').val(),
email : jQuery('#email').val(),
date : jQuery('#date').val(),
add2 : jQuery('#add2').val()
},
success : function(data){

jQuery('#container').show(0);
jQuery('#container').removeClass().addClass((data.error === true) ? 'error' : 'success').replaceWith(data.result).show(500);
if (data.error === true)
jQuery('#results_form').show(500);
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
jQuery('#waiting').hide(500);
jQuery('#container').removeClass().addClass('error').text('Please fill out all the required fields.').show(500);
jQuery('#results_form').show(500);
}
});

return false;
});

Fotiman

6:28 pm on Sep 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What do you mean "it is not reflected in the url?" What URL? Do you mean the URL shown in the browser's address bar? The point of AJAX is that it doesn't require the entire page to be refreshed... an AJAX call will never change the browser's address bar.

lobas

6:47 pm on Sep 30, 2010 (gmt 0)

10+ Year Member



Hmmm it's basically a search form, so someone from another page enters details into a search box and it loads results.php instead of results.php I need to have say /results/somevalue/anothervalue/somemorevalues/1/2 etc... which I could then copy and paste to someone which would then load the same values

Fotiman

7:33 pm on Sep 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm still not quite sure what you mean.
Without AJAX, a user would enter values in a form, press submit, and would be directed to the form's "action" page (which in theory could also redirect to a different page). With AJAX, the form is submitted via the XMLHTTPRequest object rather than via the browser, though the underlying HTTP transaction is essentially invisible to the end user (the browser does not move from it's current location). If you want to present the location of the search results to the user (using AJAX), you could serialize the form data that you're sending in the GET and create a link using that data.