在我的网页中,我有这样的脚本:
<head>
<script src="scripts/effect.js"></script>
<script>
if (document.readyState == 'complete') {
doOnLoad();
}
$(window).bind("load", doOnLoad);
function doOnLoad() {
console.log("here..");
}
</script>
</head>
effect.js文件包含如下所示的脚本:
$( document ).ready(function(){
console.log("yes");
// here I've script for reading a text file using ajax and manipulating the result from text file
$.ajax({
// code goes here
console.log("ajax");
});
});
问题是当我最初运行页面时,我没有得到结果。那时我得到控制台输出为
yes
here..
ajax
但是当我再次刷新页面时,我得到的结果和控制台打印如下:
yes
ajax
here..
window.load
完成后如何运行document.ready
。
谁能帮我解决这个问题?提前致谢。