0

I want to insert some data into database when user cuts/exits the browser or tab. This is the statement which I want to be executed.How is this possible

 _objQ117.insert();
Mangal Pandey
  • 109
  • 13
  • You can send a blank ajax request on a specific time interval and do your task at every request. If the tab is closed you will not get any further request and this way results of the previous request will sustain. This might not be a effective way but you can consider it an option. – Hossain Muctadir Nov 12 '13 at 11:26
  • That sounds nice...But I am a fresher and I don't know much about Ajax....So do help me with some code please..that will be nice of you – Mangal Pandey Nov 12 '13 at 11:29
  • This http://api.jquery.com/jQuery.ajax/ might give you a something to start with. – Hossain Muctadir Nov 12 '13 at 11:31

1 Answers1

0

I'm in no way a C# guru, but I'll try to explain the general principle.

Browsers are pretty protective of the user's data these days, though there are possibilities.

You may use something akin to onunload or onclose to send an AJAX request to the server, executing the query.

However, support of this may be spotty in certain browsers. By sending AJAX requests, say every minute or so, the server will be aware that your client is still connected--until the requests stop. An AJAX request is nothing more than a standard HTTP request created by javascript and returned as a variable(i.e. without necessarily loading an entire page, as the server only returns a small amount of result data)

nanofarad
  • 40,330
  • 4
  • 86
  • 117