On 17 Lis, 10:44, Michael Geary <m...@mg.to> wrote: > Here is how this really works: > > 1. Changes you make to the DOM always take effect immediately. If you make > any change to the DOM and then immediately follow that with code that looks > for your change, that code will indeed see the change. For example: > > $('#mydiv').html( 'hello' ); > alert( $('#mydiv').html() ); // alerts 'hello' > > 2. BUT... The browser does not refresh its display until your JavaScript > code finishes running. So the user will not see any of your changes until > then. > > 3. A synchronous Ajax call does not let your JavaScript code finish running. > In that sense it's just like your hard loop. The user will not see anything > you change in the DOM until after that call finishes and your code stops > running.
Ok... thanks... I suspected something like that... > Why do you need a synchronous Ajax call? This is a VERY bad idea. In > single-threaded browsers such as Firefox, it's not just a matter of the page > display not refreshing. Your code will completely lock up the browser's user > interface - menus and all - and not just for the current browser tab or > window, but for *all* browser tabs and windows. The script I'm doing is not for a web page but for a Windows Sidebar Gadget... in particular, a settings page for the gadget ( http://img694.image shack.us/i/clipboard1d.png/ ) so the blocking isn't a big issue since the user can't do anything with a widget if there isn't a working connection anyway... When you click on the OK button a function is called which must set a property of the closing event and beforehand I must check if the settings the user entered are correct (the connection with an external service can be established)... Here's more info about it: http://msdn.mic rosoft.com/en-us/library/bb655904(VS.85).aspx http://msdn.mic rosoft.com/en-us/library/aa359280(VS.85).aspx > Can you use the BlockUI plugin to simulate the effect you need? This would > be MUCH better than using synchronous Ajax: > > http://www.malsup.com/jquery/block/ I'll try and see what I can come up with... > If you must use a synchronous Ajax call and you want the user to see a > message you put into the DOM, then you will need to yield control after you > add the message but before issuing the Ajax call. You can do this with > setTimeout. > > Where you have code like this: > > $('#message').html( 'Sorry, dude, I will now lock up your browser' ); > $.ajax({ async:false, ... }); > > You need to change it to: > > $('#message').html( 'Sorry, dude, I will now lock up your browser' ); > setTimeout( function() { > $.ajax({ async:false, ... }); > }, 1 ); > > That will allow the user to see your message before you lock up the browser > by issuing the Ajax call. > > But what would be the point? By using setTimeout() you've made the code > asynchronous anyway. So you could just use asynchronous Ajax in the first > place, with BlockUI to give the blocking effect you want in the UI. Ok, thanks... I'll look into it... -- nowotny