• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Change cursor during Ajax

 
Hengki Widjaja
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hengki Widjaja
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 5889
63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 5889
63
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you already tried performing the next Ajax call in the callback function of the previous one?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This doesn't work. Am I missing something here?
 
Albareto McKenzie
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should show us your real code so we can help you further.
 
Hengki Widjaja
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator






 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic