gpt4 book ai didi

javascript - Prototype 的 Ajax.Request 和 Internet Explorer 8

转载 作者:行者123 更新时间:2023-11-29 18:37:41 25 4
gpt4 key购买 nike

以下代码应该在页面加载后执行 AJAX 请求,然后在弹出窗口中显示该 AJAX 调用的响应。这在 Firefox 中有效,但我不知道为什么它在 IE8 中不起作用。

<html>
<head>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript">
// Do this stuff when DOM finishes loading.
document.observe("dom:loaded", function() {
new Ajax.Request("page.html", {
onSuccess: function(response) {
alert(response.responseText);
}
});
});
</script>
</head>
<body>
</body>
</html>

page.html 只包含

hello world

我是否遗漏了一些明显的东西,或者这是原型(prototype) js 库与 IE8 不完全兼容的结果?我尝试使用最新的稳定原型(prototype)版本 (1.6.0.3) 和前沿版本 (1.6.1 RC3),但没有成功。任何帮助将不胜感激,谢谢!

最佳答案

您是在网站上还是在使用文件?我能够让您的代码在 Visual Studio 的网站上运行,但是当我从一个文件中尝试它时,我收到了“拒绝访问”错误。我怀疑由于 IE8 中的安全限制,它无法对本地文件系统中的文件执行 Ajax 请求。

下面是我在 Default.aspx 页面中用来加载 page.htm 文件的确切代码。请注意,我更改了方法——因为它不是一种形式——并且我添加了失败和异常的回调。异常回调是用本地文件为我触发的。正如我所说,它在访问同一网站中的页面时工作正常。

<script type="text/javascript">
document.observe( 'dom:loaded', function() {
new Ajax.Request("page.htm", {
method: 'get',
onSuccess: function(response) {
alert(response.responseText);
},
onFailure: function(response) {
alert(response);
},
onException: function(request,error) {
alert(error.message);
}
});
});
</script>

关于javascript - Prototype 的 Ajax.Request 和 Internet Explorer 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1122984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com