Question

Is there a way to append the var url variable to the address bar without reloading the page. It's my first time using ajax.

Edit: what is the event target node edit 2: got it, much simpler than I thought..

history.pushState(null, null, url);


        $('a[href^="/"]').unbind('click').click(function(e){
            var url = $(this).attr('href');
            e.preventDefault();
            $.ajax({
                url: url,
                success: function( result ){
                    response = $('<div id="temp-ajax-response-holder" style="display: none;"></div>');

                    response.html(result);
                    if (response.find('#ajax').first().find('.header').length > 0 ) $('body').removeClass("home archive").addClass('single');
                    else if(response.find('#ajax').first().find('.archive_title').length > 0 ) $('body').removeClass("home single").addClass('archive')
                    else $('body').removeClass("single archive").addClass('home');
                    if (response.find('#ajax').first().find('.header').length > 0 )
                        $('body').attr('class', 'single single-post');
                    $('body #ajax').html(response.find('#ajax').first().html());
                    bindHTML();
                    response.html('');

                }
            });
    });
Était-ce utile?

La solution

First thing coming to my mind would be the History API. If your browser supports it, you can change the location in the address bar and even make it available through the browser history. This allows to use the back-button for instance.

history.pushState(null, null, yourNewUrl);

For further introduction I'd recommend reading http://diveintohtml5.info/history.html.

Autres conseils

YES , There is, Only for browser Supporting HTML 5.

There is a push state. check this link

http://diveintohtml5.info/history.html

Demo is

http://html5demos.com/history

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top