Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 125
  • Last Modified:

Javascript onUnload

If I put a <body onUnload="do_unload();"> in an HTML page, can the do_unload function do ajax calls to upload data from Javascript arrays to the web server (using php scripts on the web server)?

Then when it completes, do a "return true"; and the Unload will occur, the browser remembering all the other details of the unload?

Thanks
0
Richard Korts
Asked:
Richard Korts
  • 4
  • 3
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
You'll have to test it yourself since we can't know what you are going to put in your code.  I woudn't even guarantee that all the browsers will act the same.  But if you do anything that seems to prevent someone from leaving your site or even your page, it is likely they won't come back.  'onUnload' has a bad reputation for alienating visitors who are trying to go somewhere else.
0
 
Richard KortsAuthor Commented:
Dave Baldwin,

It's  a private application with a "captive" audience. I thought of this as a way to save information. I could go into all the details, but it takes too long.

I know what you mean. Like "Are you sure you want to leave this page" and all that kind of crap.
0
 
Dave BaldwinFixer of ProblemsCommented:
Just try it then.  I don't see that that would first choice though.  If they close the browser instead of going to a different page, it won't work.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Richard KortsAuthor Commented:
Dave,

Here is what I'm trying to do. I welcome alternate suggestions.

We have an app that is browser based, used in the field by service techs that have iPads. It's php with a MySQL database. The iPads use Safari (could use Chrome if necessary).

Of course in the field, there is often no WiFi, so they have slow access.

I originally designed things to work by accessing database tables as need be.

For example, techs use parts in some of their jobs. One feature of the add parts is parts search; you type in any few letters, click search & it finds all parts that have those characters in their description. Of course it goes to the server and does a SQL like "SELECT * from parts where pdesc like '%xxx%'". If any found, displays the list in a dropdown, they pick what they want.

If no WiFi, techs experience too long wait times, do a refresh, things get screwed up, have to start over, get annoyed at the stupid people who built this (me).

So what I am trying is to do the ENTIRE parts thing in the browser using Javascript arrays and local storage (HTML 5). I load the entire parts table into local storage (~ 600 rows) when the tech logs in, then access it as need be, using Javascript arrays, etc.

I want to let them add & modify the parts needed for a specific Work Order WITHOUT round trips to the server. Then when done, they can click a "Done" button, select another menu option, etc.

So I'm thinking whenever they do one of those things, the page unloads, I can capture that Unload & using ajax, update the SERVER parts table for that SPECIFIC workorder with the parts added, modified or deleted in the session. There may be a pause, but they WON'T loose their work.

Your thoughts?
0
 
Dave BaldwinFixer of ProblemsCommented:
Since as you have described, they often lose their connection, even 'onunload' isn't going to send the data back to the server at times.
0
 
Richard KortsAuthor Commented:
Dave,

So what would you recommend?

I'm not sure they lose the connection, I think it's more like they think it's too slow & try "something" like refresh, etc.
0
 
Dave BaldwinFixer of ProblemsCommented:
The obvious thing is an app that runs on their device and reports back to the server only when they have a connection
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now