*
The moose likes HTML, CSS and JavaScript and the fly likes Change cursor during Ajax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Change cursor during Ajax " Watch "Change cursor during Ajax " New topic
Author

Change cursor during Ajax

Hengki Widjaja
Ranch Hand

Joined: Oct 31, 2011
Posts: 44
I've been struggling with how to change the cursor when AJAX is executing and change back to normal after it's completed. I'm using async:false in jquery. Thnks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Why have you turned aysnch off? That is not recommended for almost all situations.

And you can use the event callbacks to change the CSS when the request starts and completes.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Hengki Widjaja
Ranch Hand

Joined: Oct 31, 2011
Posts: 44
I'm not using CSS for this particular page. I turned off async because it produced unpredictable result. There's a sequence of code that sometimes works and sometimes produces error when async is true. Is there no other solution? I must use css? thanks
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3615
    
  14

The reason you're getting unpredictable results is because you're probably not using callbacks properly. Instead of disabling the option, use it correctly.

And why are you not using CSS? It's almost like saying, hey I want to make a web page, but I'm not using HTML.
Hengki Widjaja
Ranch Hand

Joined: Oct 31, 2011
Posts: 44
I have sequential AJAX calls where the each call depends on the previous ones (except for the first call). without asych:false, everything breaks down. I'm thinking about something more like document.body.style.cursor, but it didn't work out. Currenly it's only a page with a background image and a simple button (that invokes series of ajax calls). That's why I don't use css (yet).
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3615
    
  14

Have you already tried performing the next Ajax call in the callback function of the previous one?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Stephan is speaking wisely. You should be triggering Ajax calls that need to be sequential in the callbacks. And CSS should be used for all styling.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Using a synchronous call basically locks up the page and it will not update. So changing the cursor and having the screen update is in a race condition with the Ajax call locking the browser.

synchronous calls are bad and there are always solutions to make the asynchronous, you just have to code them differently.

Eric
Hengki Widjaja
Ranch Hand

Joined: Oct 31, 2011
Posts: 44


This doesn't work. Am I missing something here?
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
I have no idea about jQuery, but as per the documentation: http://api.jquery.com/jQuery.ajax/ it should be something more like this:



And what the other guys are suggesting is that you invoke the next AJAX request in that success function.
Hengki Widjaja
Ranch Hand

Joined: Oct 31, 2011
Posts: 44
Even for AJAX that's not sequential, if I set aysnc:true, it won't work. I'm filling two dropdowns. I call ajax to retrieve the datas from server to then be filled into the dropdowns. the ajax for both calls are exactly the same. In this case, the order of both calls doesn;t really matter since they don't need data from each other. So I must set aysync false; I've tried with true, doesn't work. the dropdowns don't get filled. And I've tried the method above, still not working.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
I think you should show us your real code so we can help you further.
Hengki Widjaja
Ranch Hand

Joined: Oct 31, 2011
Posts: 44






 
Don't get me started about those stupid light bulbs.
 
subject: Change cursor during Ajax