• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

ajax write form data to file javascript confirm box

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
hibbsusan
Asked:
hibbsusan
  • 4
1 Solution
 
hibbsusanAuthor Commented:
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
 
nap0leonCommented:
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
 
hibbsusanAuthor Commented:
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
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
leakim971PluritechnicianCommented:
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
 
hibbsusanAuthor Commented:
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
 
hibbsusanAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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