我有一个 ajaxed 页面,但文档就绪代码将无法运行。我在 IE7 中运行。我没有收到警报,但“页面在这里”显示正常。方法“ajax”是我写的一个实用方法。它适用于我所有的 ajax 调用,所以我知道这不是问题。我只是无法让我的 javascript 运行。为什么我的 javascript 不能运行?
AJAX 页面
<script src="Utilities/Javascript/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
alert("RUN PLEASE");
</script>
Page is here
主页
<html>
<head>
<script src="Utilities/Javascript/Utilities.js"></script>
<script src="Utilities/Javascript/jquery-1.7.1.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function () {
ajax("scrolltest.aspx", "divy2");
});
</script>
<div id="divy2">
</div>
</body>
</html>
来自 Utilities.js 的 ajax 方法
/*
* Ajax page loads with url and updates element's innerHtml
* @param url : URL to call for ajax page load
* @param element : Element ID to be updated
*/
function ajax(url, element) {
var ajx;
if (window.HXMLHttpRequest) {
ajx = new XMLHttpRequest();
}
else {
ajx = new ActiveXObject("Microsoft.XMLHTTP");
}
ajx.open("GET", url, true);
ajx.setRequestHeader("X-Requested-With", "XMLHttpRequest");
ajx.onreadystatechange = function () {
if (ajx.readyState == 4 && ajx.status == 200) {
document.getElementById(element).innerHTML = ajx.responseText;
}
else if (ajx.readyState == 4 && ajx.status == 400) {
alert("Page Error. Please refresh and try again.");
}
else if (ajx.readyState == 4 && ajx.status == 500) {
alert("Server Error. Please refresh and try again.");
}
else if (ajx.readyState == 4) {
alert(ajx.status + ":" + ajx.statusText);
}
}
ajx.send();
}