ajax 请求后未触发 IE document.ready()

发布于 2024-09-26 15:46:00 字数 1420 浏览 1 评论 0原文

document.ready() 在 IE 中的 ajax 请求后不会触发,但在 FF 和 chrome 中很有用。 我有两个文件。第一个文件(test.jsp)只有一个提交按钮。 onclick它从struts加载第二个文件(result.jsp)。 。 这两个文件是

test.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>

result.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() 行中预期的对象。 但是如果我们刷新页面就可以了......

任何帮助将不胜感激......

document.ready() not triggered after ajax request in IE but work a charm in FF and chrome.
I have two files. First file(test.jsp) just has a submit button. onclick it loads from struts the second file(result.jsp). . the two files are

test.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>

result.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>

when result.jsp loads alert("success"); is called....
This works well in FF and chrome.
But not in IE. the alert doesnt pop up. Displays error as Object expected i document.ready() line.
But works if we refresh the page....

Any help will be appreciated...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

开始看清了 2024-10-03 15:46:00

当我执行 ajax 请求时,我总是添加一个随机数/字符串作为 ajax url 的参数。这几乎总是修复我的 IE 相关错误,因为它强制 IE 加载重新加载页面而不是使用缓存中的错误。

When I do an ajax-request I always add a random number/string as parameter to the ajax url. This almost always fixed my IE related errors because it forces IE to load reload the page and not use one from the cache.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文