document.ready() 在 IE 中 ajax 请求后不会触发,但在 FF 和 chrome 中很有用。 我有两个文件。第一个文件(test.jsp)只有一个提交按钮。 onclick它从struts加载第二个文件(result.jsp)。 。这两个文件是
测试.jsp
<html>
<head>
<script type="text/javascript" src="/js/jquery-1.2.6.min.js"/></script>
<script type="text/javascript" src="/js/api.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#test").click(function()
{
var path = "/TestAjax.do"
$.get(path,function(data)
{
document.write(data);
});
});
});
</script>
</head>
<body>
<div><h3>Hello World</h3><br/>
<input type="button" id="test" value="submit"/>
</div>
</body>
</html>
结果.jsp
<html>
<head>
<script type="text/javascript" src="/js/jquery-1.2.6.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
alert("success");
});
</script>
</head>
<body>
<div><h3>result</h3><br/>
<!--input type="button" id="test" value="submit"/-->
</div>
</body>
</html>
当result.jsp加载时alert("success");叫做.... 这在 FF 和 chrome 中效果很好。 但在 IE 中不行。警报不会弹出。将错误显示为 document.ready() 行中预期的对象。 但是如果我们刷新页面就可以了......
任何帮助将不胜感激...
最佳答案
当我执行 ajax 请求时,我总是添加一个随机数/字符串作为 ajax url 的参数。这几乎总是修复我的 IE 相关错误,因为它强制 IE 加载重新加载页面而不是使用缓存中的错误。
关于jquery - ajax 请求后未触发 IE document.ready(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3881725/