Site Navigation

Showing posts with label AJAX. Show all posts
Showing posts with label AJAX. Show all posts

Tuesday, May 13, 2008

bug 122 - in IE an HTTP 204 status may magically become a 1223 status

Issue: #122
Affects: IE6, IE7, IE8?

If you send an XMLHttpRequest that only returns headers (e.g. no content), and you are looking for a 200 status, you'll end up getting a 204 status. In itself that's just fine, but in IE that status might become a 1223 status instead!


Known Workarounds: None. Adjust your response tests as needed to handle this additional IE status.



Related Issues: None.

Bug/Site Feedback |
Submit a bug

Sunday, April 6, 2008

bug 284 - no native XMLHttpRequest object in IE

Issue: #284
Affects: IE6, IE7, IE8

What!? you say? "They added this in IE7!" - Well yes, no, not quite!

Microsoft did add a non-ActiveX version of XMLHttpRequest ("XHR") so that if a user had turned off ActiveX for security reasons, AJAX would still work (this was a good thing).

However there is a key feature of JavaScript Objects that makes them so useful is that you can Prototype on them to add properties, methods, expando properties, or even subclasses. In addition it doesn't extend from Object, thus any prototyping done there won't be available on XHR, and none of the methods on XHR are exposed.

In IE6, the XHR Object was an ActiveX control only, in IE7 they added a "native" one, but it was just access to the XHR Object that didn't require ActiveX. In IE8 Beta 1 there are no changes, but In IE8 RTM, will we see a true native XMLHTTPRequest Object?


Example:

Lets say you wanted to improve the user experience when an AJAX request is sent to the server.


  • You might want to set a timeout that a response is expected by, and if it isn't cleared, automatically call an error handler.

  • You might want to queue up/discard duplicate requests if the browser has already sent a request in, and is waiting for a response.

  • You might want to add some debug capabilities to trace the progress of your AJAX Requests

  • Since an AJAX request might be very expensive on your server, you might want to add the ability to pass in a "cancellation" request, that is "tied" to the original request... this way if the user closes a window, or runs another query, you could send a quick "one-way" request to the server to cancel the first request.



In any of these cases, being able to store applicable info on the XHR object is ideal, and adding methods would enable callbacks to be self-contained.


<script type="text/javascript">
var myXHR = new XMLHttpRequest();
myXHR.lastAccess = null;
myXHR.requestTimeout = 15000;
myXHR.requestTimeoutHandler = myTimoutHandler;
</script>


The above will fail in IE, since expando's and prototypes are not an option.

Want to see what Properties/Methods are exposed on XMLHttpRequest in your browser?
Click the button to find out! (check in other browsers too)


(PS If you subscribe to this Blog via RSS/Atom, please try the button on the Blog site as we needed to update the sample several times to overcome some Blogger auto-line-break issues. - thanks)


Known Workarounds: None.


Related Issues: (bug 186), (bug 181).

Bug/Site Feedback |
Submit a bug

Friday, November 9, 2007

bug 146 - IE caches your AJAX

Issue: #146
Affects: IE6, IE7

So, you're doing all kinds of funky stuff with AJAX now, and you've come to notice in your testing that sometimes Internet Explorer is not really hitting your server, but instead caching your AJAX calls?! Even if you set the no-cache header!

Addendum:
As Eric Lawrence points out over on his site Enhance IE, this bug (#IE0001) is only a "bug" when IE caches and a query string is present; The HTTP standard does not prohibit caching if a query-less GET returns no cache indicators.

Known Workarounds: Two. If you are calling a particular request repetitively, but are expecting different results, add a unique parameter to the request.


Example Workaround Code:

<script>
var url = 'http://www.example.com/dir/foo?param1=a¶m2=b';
//add a unique param to the request (adjust to suit)
url += '&guid=' + new Date().getTime();
</script>




Known Workaround: Second Option.
Set the full cache header information, not just the no-cache.


Example Workaround Code:

<!-- This example is using PHP -->
<?php
header("Pragma: no-cache");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Cache-Control: no-store, no-cache, must-revalidate");
?>





Related Issues: None.