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() {
            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').removeClass().addClass((data.error === true) ? 'error' : 'success').replaceWith(data.result).show(500);
                if (data.error === true)
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                jQuery('#container').removeClass().addClass('error').text('Please fill out all the required fields.').show(500);
        return false;

Recommended Answers

All 5 Replies

...for some reason it is not reflected in the url

ajax requests do NOT change the url that is currently loaded/displayed in the address bar. The requests occurs "in the background". Hence the url in address bar remains unchanged. IF it did so, then the whole page/window would reload, which defeats the purpose of ajax.

Yeah so can i not show the URL in the address bar with the get request details? so i can link people directly to specific get requests?

Yeah so can i not show the URL in the address bar with the get request details?

I don't understand what you are asking. IF you arrive at page1.php and you need data/info from page2.php and you do NOT want page2.php in the address bar, then when you send the ajax request to page2.php, then the address bar will remain as page1.php. In other words, page2.php remains "hidden".

Now if you want to pass parameters to page2.php, then instead of arriving at page1.php, your users should be arriving to something SIMILAR to page1.php?section=comments then before you send the ajax request, retrieve the string after the quation mark from location.href:

var params = location.href.substring(location.href.indexOf('?') )

then on the server you should be able to see those parameters and send content specific for those parameters.

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

search for "url rewrite tutorial". Basically your server will "look" at the url first, and (as long as you provide the correct/necessary rewrite rule), internally it can/will send the request to results.php?params=somevalue anothervalue, etc.

If you are using an apache server, chances are you already have that capability. If you are not the webmaster/administrator of the server, contact the admin to find out if your server supports url rewrite.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.