Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ajax write form data to file javascript confirm box

Posted on 2011-10-13
6
Medium Priority
?
378 Views
Last Modified: 2012-08-14
I have a simple confirm button

var leave=confirm("are you sure you want to leave? Information you have entered will be lost!");
if (leave==true)
  {
return true;
  }
 else
  {
  return false;
  }
}

Open in new window


Is there anyway to use ajax (jquery+ajax is my only ajax experience) to write some data to a file if the user decides to leave the page? That way I can collect his or her name, IP, &c. so I have a confirmation who has cancelled the order mid-way through. I was thinking about collecting the data in the form fields with jquery before I wrote to the file, if that makes any difference.

Thanks!!
0
Comment
Question by:hibbsusan
  • 4
6 Comments
 

Author Comment

by:hibbsusan
ID: 36963766
and by write data to a file, i mean, create a txt file on my server (/incomplete_order_logs/ or something), and write to that file.

pardon me: that was pretty unclear the first time.

Thanks!
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 36963798
I presume you already have the timing of the Confirmation Dialogue worked out, etc. so that it fires appropriately.  Also, I presume you already have the information in session that you want to write.

If so, before you "return true", fire the AJAX event that passes the information to your server-side page that writes the file.
0
 

Author Comment

by:hibbsusan
ID: 36963968
I presume you already have the timing of the Confirmation Dialogue worked out,
yes.

Also, I presume you already have the information in session that you want to write.
yes.

If so, before you "return true", fire the AJAX event that passes the information to your server-side page that writes the file.
This is exactly what I want to do, but I haven't got any idea what the ajax code should be!

Thanks!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 36964053
save_with_ajax_synchronous_call();
var leave=confirm("are you sure you want to leave? Information you have entered will be lost!");
if (leave==true)
  {
return true;
  }
 else
  {
  undo_last_save();
  return false;
  }
}
0
 

Author Comment

by:hibbsusan
ID: 36964889
when i add this to the window.onbeforeunload event, it pops up the confirm box both when the pages loads and unloads.. any idea why?
0
 

Author Comment

by:hibbsusan
ID: 36964913
and chrome blocks alerts and confirms. Any way around that?? the code below works in safari, but not chrome..


$(window).unload(function() {
  var leave=confirm("are you sure you want to leave? Information you have entered will be lost!");
if (leave==true)
  {
return true;
  }
 else
  {
  return false;
  }

});

Open in new window

0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month20 days, 14 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question