문제

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('');

                }
            });
    });
도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top