Вопрос

Here is an example:

http://develop.davzy.com/ajaxtest/#!/contents

It works on every browser except for internet explorer. Here's the code:

<!doctype html>
<html>
    <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
        <script>
            $(document).ready(function(){
                    $('div').load('contents.html');
            });
        </script>
    </head>
    <body>
        <div>This message will change if the call is made correctly.</div>
    </body>
</html>

The contents of contents.html are If you're still on test.html, then this AJAX call worked.

Obviously I plan on using hashtag navigation but what's weird is if you remove the /#!/contents from the url it WILL work in IE. But if you leave it there even though it has NOTHING to do with the code it still doesn't work. Looking at the headers I'm getting 406 errors. Help :(

Это было полезно?

Решение

Per my comment above: the issue seems to be that IE9 preserves the "#!/contents" part of the URL when creating the "Referer" header. The jqXHR object that jQuery AJAX wraps around the browser's XMLHTTPRequest object exposes a setRequestHeader method that might let you change the Referer header so that it doesn't cause the 406 error. You might try adding the following code to your script, if you don't care about an accurate Referer header:

$('div').ajaxSend(function(evt,jqXHR) {
  jqXHR.setRequestHeader(jqXHR.getResponseHeader("Referer").replace(/#/g,''));
});

This will create an ajaxSend callback for all AJAX operations executed against divs that will strip hash marks out of the Referer header... I haven't had time to test this, but in theory it should work.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top