6

Can anyone enlighten me as to why the following code won't work in IE7 but it works just fine in Chrome/Firefox?

$(document).ready(function(){
  $.ajax({
    type: "POST",
    dataType: "text",
    cache: false,
    url: "/ajax/ajax.asp",
    data: "cmd=check_forfeits",
    success: function(msg) {
      return false;
    }
  });
});

The javascript error IE throws out is 'Permission Denied'

If I remove that bit of code from the JS file for the page in question the page works just fine, no errors, so the error lies in that bit of code I believe.

:::UPDATE:::

Something else that is a little strange is that when I refresh the page (in IE7) I get no javascript errors and this code seems to work correctly. So it's as if the first time the page loads this code snippet errors but after that it runs just fine.

:::UPDATE:::

Here are the fiddler posts for this page from IE7:

#   Result   Protocol   Host                 URL
1   200      HTTP       192.168.47.13:8000   /
2   304      HTTP       192.168.47.13:8000   /js/jquery-1.4.1.js
3   200      HTTP       192.168.47.13:8000   /js/index.js
4   304      HTTP       192.168.47.13:8000   /js/jquery-1.4.1.js
5   200      HTTP       192.168.47.13:8000   /js/index.js
6   304      HTTP       192.168.47.13:8000   /css/main.css
7   304      HTTP       192.168.47.13:8000   /css/grid.css
8   304      HTTP       192.168.47.13:8000   /images/banner.jpg

Here are the fiddler posts for this page from Firefox:

#   Result   Protocol   Host                 URL
1   200      HTTP       192.168.47.13:8000   /
2   304      HTTP       192.168.47.13:8000   /js/jquery-1.4.1.js
3   304      HTTP       192.168.47.13:8000   /js/index.js
4   304      HTTP       192.168.47.13:8000   /css/grid.css
5   304      HTTP       192.168.47.13:8000   /css/main.css
6   304      HTTP       192.168.47.13:8000   /images/banner.jpg
7   200      HTTP       192.168.47.13:8000   /ajax/ajax.asp
Ryan
  • 6,756
  • 13
  • 49
  • 68
  • 1
    FWIW, the cache option is 'cache' not 'cached', although I doubt that would break the call. – BBonifield Feb 23 '10 at 14:17
  • +1 nice catch. Fixed this but as you said... it wasn't the deal breaker. – Ryan Feb 23 '10 at 14:32
  • Are you able to instantiate an ordinary XMLHttpRequest on your machine? Try `xhr = XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP");` and see if you get the same error. – Andy E Feb 23 '10 at 14:51
  • @Andy E: When I input your line of code I get the same error. You may be on to something. – Ryan Feb 23 '10 at 15:15
  • @Ryan: It looks like you have native XMLHttp support and ActiveX controls disabled, but i'm not entirely sure (hence not posting this as an answer). See http://msdn.microsoft.com/en-us/library/ms537505(VS.85).aspx. – Andy E Feb 23 '10 at 15:31
  • @Andy E: Check IE7 Internet Options for those features and they both appear to be enabled. As I said, on an initial visit to the page I get this error however if I refresh the page I get no errors. – Ryan Feb 23 '10 at 15:56

6 Answers6

8

if people happen to find this page because they're experiencing the same error - I just found another cause / solution for IE7 failing with this "PERMISSION DENIED" error and succeeding on a refresh.

Make sure that if you're using this in your <head> tag:

<meta http-equiv="content-type" content="text/html;charset=utf-8" />

Note that it does not have any capital letters or a space after the ";". Our site had this version:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

and that caused the same behavior when making AJAX calls.

Hopefully this helps someone else, because we just spent about 6 hours figuring this out.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
Jason
  • 121
  • 1
  • 3
2

I ran into the same issue.

I did a work around to resolve the issue. I wrote the code to make the ajax call without using jQuery (created XMLHttpObject, onreadystatechange, etc). Then I used jQuery to parse the XML.

For some reason the jQuery's ajax doesn't work well with IE7.

You don't really get an error in IE7 but if you debug it then you'll see that the server is never hit and or code never reaches the success block.

L4ndo
  • 46
  • 2
0

Something inappropriate could be in your page, the reason why I encountered this issue is that I use the document.write("<style></style") when I use the JqueryTool API at the same page.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Aiping He
  • 491
  • 1
  • 6
  • 10
0

there's a line in jquery 1.9.1 which isnt used afterwards but which throws an exception: line 2582, column 4 in jquery-1.9.1.js

this happens only for IE7 and not IE8 or above, and stops it loading the rest of the jquery stuff. using IE7 compatibility mode in IE9 i found the line of code throwing the exception then commented it out in jquery1.9.1 as follows:

// IE6/7 do not support getting/setting some attributes with get/setAttribute
if ( !getSetAttribute ) {

    // Use this for any attribute in IE6/7
    // This fixes almost every IE6/7 issue
    nodeHook = jQuery.valHooks.button = {
        get: function( elem, name ) {
            var ret = elem.getAttributeNode( name );
            return ret && ( name === "id" || name === "name" || name === "coords" ? ret.value !== "" : ret.specified ) ?
                ret.value :
                undefined;
        },
        set: function( elem, value, name ) {
            // Set the existing or create a new attribute node
            var ret = elem.getAttributeNode( name );
            if ( !ret ) {
                elem.setAttributeNode(
                    (ret = elem.ownerDocument.createAttribute( name ))
                );
            }

            //LB - 19/04/2013 - removed for IE7 compatibility.
            //ret.value = value += "";

            // Break association with cloned elements by also using setAttribute (#9646)
            return name === "value" || value === elem.getAttribute( name ) ?
                value :
                undefined;
        }
    };
Hugo Dozois
  • 8,147
  • 12
  • 54
  • 58
Les
  • 1
  • 1
0

newest edit

I found some talk about this here: http://zacster.blogspot.com/2008/10/jquery-ie7-load-url-problem.html and other places. It seems the problem has to do with the IE7 cache. If you make the URL unique that might fix the problem (eg add a timenow=09472345 to the end of the request string.)

initial response

Are you sure the name is .asp? I would expect to see .aspx or some other extension handled by .net If this is what you need then you probably have to enable .asp in IIs

then I read the question again

I see that it works in other browsers so it can't be my original comment... download fiddler and see how the request is different from IE and other browsers.

http://www.fiddler2.com/fiddler2/

Hogan
  • 69,564
  • 10
  • 76
  • 117
  • After comparing the posts made in both IE7 and Firefox the only difference is that Firefox has one additional post... the post to /ajax/ajax.asp... that post never gets made in IE7.. probably due to the 'Permission Denied' error. – Ryan Feb 23 '10 at 14:31
  • What are the prior posts? Also, do you have a DC -- it might be that IE is using windows authentication and the other isn't -- you have rights as non-windows user but your domain name does not have rights. – Hogan Feb 23 '10 at 14:37
  • I've edited my original post above to include the fiddler logs for the two browsers. – Ryan Feb 23 '10 at 14:47
  • @Ryan: see my newest edit, I believe I found a reference that solved your problem. – Hogan Feb 23 '10 at 14:49
  • @Hogan: if you look at the fiddler logs the post isn't even ever made to the ajax page in IE7 so I don't think changing the url would help in this instance. – Ryan Feb 23 '10 at 15:16
  • @Ryan: actually my reading of that page suggested this is the expected fiddler behavior. Because IE uses a local cached version it never checks the server, thus never shows up in fiddler. – Hogan Feb 23 '10 at 15:50
  • @Hogan: gave it a try and still no deal. – Ryan Feb 23 '10 at 20:37
0

I had an issue with the AJAX call in jQuery in IE7 as well. I found out what my issue was and not sure if its related to yours or not.

I was not putting the protocol in the URL and had extra slashes in IE 7 such this:

//www.mywebsite.com/products//json.php

which works everywhere else besides shIEt

Once I added the protocol and took away extra slashes it all worked fine.

King Friday
  • 25,132
  • 12
  • 90
  • 84