This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Sleep Method in JavaScript

 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my projects, my client wants a functionality to save the data in a table before the user is move to another page. So I thought calling window.onbeforeunload function will help me.

However I want this function to wait, until user selects his options. I tried is there any method is available to sleep the current function until the user triggers his options.

I tried with a while loop, but it really gone mad by hanging the browsers.

I feel it a real challenge to implement this. Any thoughts will be appreciated.

[ March 31, 2008: Message edited by: Mohammed Yousuff M N ]
 
Marshal
Posts: 67343
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no concept of synchronous wait in the browsers. You didn't explain what you are trying to accomplish very clearly. Perhaps a better explanation would help?
[ March 31, 2008: Message edited by: Bear Bibeault ]
 
Mohammed Yousuff
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, if a user updates some data in a registration fields, and then clicks a new links with out saving the updated data (saving data happens using AJAX). So user shoud be notified before he is moving into another page.

The alert must custom alert, where a DIV will shown as a layer in the page and user will give his choice what to save the or not.

I believe I explain the scenario, please let me know if you have any comments.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try and fire off the Ajax request as a synch call, that might do the trick. There are downsides to synch calls, but this mihgt be your only optoion other than a nice discriptive message on the onbeforeunload explaining them that they need to go back and save.

Eric
 
Mohammed Yousuff
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Eric for your updates. is there any call back functionality available in JavaScript ...

i think that may also help me to do this ..
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, I should have used spell check on my last post!

I am not sure what you are talking about.

My only suggestion was to try to set the asynch flag to true so you force the browser to wait until the response comes back before moving on. I am not sure if the browser will actually wait, but it might be a good thing to try out if you want to go that route. It is not hard to build a quick test script and see what happens.

Eric
 
Mohammed Yousuff
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric if I was not wrong, Ajax request will help me to wait for some time in my current function, until the server timeout happens. But what if the user is not giving any values for a long time.

Will this technique will help me. Please advice if was wrong �

Thanks a lot for your comments.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Mohammed Yousuff M N",
Please check your private messages regarding an important administrative matter.
-Ben
 
Mohammed Yousuff
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any API in prototype which will help me to sleep the current function for few sec..
 
Does this tiny ad smell okay to you?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!