javascript - Prototype's Ajax.Request and Internet Explorer 8 - Stack Overflow

The following code is supposed to perform an AJAX request after the page loads, and then display the re

The following code is supposed to perform an AJAX request after the page loads, and then display the response of that AJAX call in a popup. This works in Firefox, but I have no idea why it does not work in 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 just contains

hello world

Am I missing something obvious or is this a result of the prototype js library not being fully patible with IE8? I tried this with the latest stable prototype release (1.6.0.3) and the bleeding-edge version (1.6.1 RC3) with no luck. Any help would be much appreciated, thanks!

The following code is supposed to perform an AJAX request after the page loads, and then display the response of that AJAX call in a popup. This works in Firefox, but I have no idea why it does not work in 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 just contains

hello world

Am I missing something obvious or is this a result of the prototype js library not being fully patible with IE8? I tried this with the latest stable prototype release (1.6.0.3) and the bleeding-edge version (1.6.1 RC3) with no luck. Any help would be much appreciated, thanks!

Share Improve this question edited Dec 28, 2011 at 21:51 Rob W 349k87 gold badges807 silver badges682 bronze badges asked Jul 14, 2009 at 1:13 MatthewMatthew 6,4969 gold badges48 silver badges62 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 2

Are you doing this in a web site or using a file? I was able to get your code working in a web site in Visual Studio, but when I tried it from a file I got an "Access Denied" error. I suspect that it is not able to do an Ajax request to a file in the local file system due to security restrictions in IE8.

Here's the exact code I used in my Default.aspx page to load the page.htm file. Note that I changed the method -- since it's not a form -- and I added callbacks for failure and exceptions. The exception callback was what got triggered for me with a local file. As I said, it works fine when accessing a page in the same web site.

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

Just an aside to the existing answer, and just wanted to mention, that IE8 does some crazy caching when you use 'get' in your Ajax calls. My web application worked fine in FF, but in IE8, some of the ajax calls were never made. I changed the method: from 'get' to 'post' and all was well.

method: 'post'

Also, to further ensure no funny business in IE8 with session variables, put the following meta tags in the head of your html pages.

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745463463a4628811.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信