【发布时间】:2014-02-25 05:14:08
【问题描述】:
有没有办法在不重新加载页面的情况下将var url 变量附加到地址栏。这是我第一次使用ajax。
编辑:事件目标节点是什么 编辑2:明白了,比我想象的要简单得多..
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('');
}
});
});
【问题讨论】:
-
这篇文章可能有用...stackoverflow.com/a/3354511/665261