javascript-为什么jQuery .load()触发两次?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-为什么jQuery .load()触发两次?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1904字,纯文字阅读大概需要3分钟。
内容图文
![javascript-为什么jQuery .load()触发两次?](/upload/InfoBanner/zyjiaocheng/651/44cab97102c641de8c7e7ce46d46b1ed.jpg)
我正在将jQuery 1.4与jQuery History结合使用,并试图弄清为什么Firebug / Web Inspector在每个页面加载时显示2个XHR GET请求(访问我的网站首页(/或/#)时,该请求数量是原来的两倍).
例如在启用Firebug的情况下访问this(或任何)页面.
这是已编辑/相关的代码(请参见full source):-
$(document).ready(function() {
$('body').delegate('a', 'click', function(e) {
var hash = this.href;
if (hash.indexOf(window.location.hostname) > 0) { /* Internal */
hash = hash.substr((window.location.protocol+'//'+window.location.host+'/').length);
$.historyLoad(hash); return false;
} else if (hash.indexOf(window.location.hostname) == -1) { /* External */
window.open(hash); return false;
} else { /* Nothing to do */ }
});
$.historyInit(function(hash) {
$('#loading').remove(); $('#container').append('<span id="loading">Loading...</span>');
$('#ajax').animate({height: 'hide'}, 'fast', 'swing', function() {
$('#page').empty(); $('#loading').fadeIn('fast');
if (hash == '') { /* Index */
$('#ajax').load('/ #ajax','', function() { ajaxLoad(); });
} else {
$('#ajax').load(hash + ' #ajax', '', function(responseText, textStatus, XMLHttpRequest) {
switch (XMLHttpRequest.status) {
case 200: ajaxLoad(); break;
case 404: $('#ajax').load('/404 #ajax','', ajaxLoad); break; // Default 404
default: alert('We\'re experiencing technical difficulties. Try refreshing.'); break;
}
});
}
}); // $('#ajax')
}); // historyInit()
function ajaxLoad() {
$('#loading').fadeOut('fast', function() {
$(this).remove(); $('#ajax').animate({height: 'show', opacity: '1'}, 'fast', 'swing');
});
}
});
一些注意事项可能会有所帮助:-
>在默认/标准.htaccess中使用WordPress
>我仅通过JavaScript(PE)将/ links-like / this重定向到/#links-like / this
>我通过window.location.replace(addr);实现了上述目标而不是window.location = addr;
>如果需要,请随时访问my site.
提前致谢.
解决方法:
我认为您已经回答了自己的问题:
“I’m redirecting
/links-like/this
to/#links-like/this
via JavaScript only (PE)”
内容总结
以上是互联网集市为您收集整理的javascript-为什么jQuery .load()触发两次?全部内容,希望文章能够帮你解决javascript-为什么jQuery .load()触发两次?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。