Ajax not asynchronous in IE?
Hi,
I'm having (once again) tremendous problems with IE (7), trying to create an application that behaves properly.
This time, it's with Ajax calls triggered by a button click, which do not behave asynchronously.
Here is the highlight of what I'm trying to achieve:
- a button clicked sends an ajax call to the server
- whilst the call is made and until the callback function has returned (or an error has been identified), a "wait" animation is triggered. (in the case below, simulated by appending a status in a div)
To achieve this, I decide to use .ajaxStart(), .ajaxStop() and .ajaxError() to trigger the wait animation.
It works perfectly in FF and Chrome, but (as usual) not in IE. In IE, when I press the button, the button remains depressed until the ajax call is finished, and then all statuses are dumped at once onto screen. Not very asynchronous...
Here is my code:
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Ajax test in IE</title>
- <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
- <script type="text/javascript">
- $(function(){
- $('body')
- .ajaxStart(function() {
- $('#status').append("Started ajax call - ");
- // alert('Started');
- })
- .ajaxStop(function() {
- $('#status').append("Stopped ajax call - ");
- })
- .ajaxError(function() {
- $('#status').append("Error in ajax call - ");
- });
- $('#load-button').click(function(){
- var bla="bla";
- $.ajax({
- type: "get",
- url: "http://some-addres2s/getsomeinfo.html",
- async: false,
- success: function(data) {
- $('#result').append(data);
- }
- });
- });
- });
- </script>
- </head>
- <body>
- <div><b>Status:</b> <span id="status"></span></div>
- <div>
- <input type="button" value="ajax call" id="load-button"/>
- </div>
- <div><b>Result:</b> <span id="result"></span></div>
- </body>
If I uncomment line 11 and uncomment the alert, it seems that this forces IE to do things in the proper order. Obviously that's not a solution however...
What on earth am I doing wrong?
Will I have to (once again) write IE-specific code to get things working properly?