<p>I have an <a href="http://www.sencha.com" rel="nofollow noreferrer">ExtJS</a> grid on a web page and I'd like to save some of its state information back to the server when the users leaves the page. 
Can I do this with an Ajax request onUnload? 
If not, what's a better solution?</p>

[{'answer_id': 73371, 'author': 'Jim', 'author_id': 8427, 'author_profile': 'https://Stackoverflow.com/users/8427', 'pm_score': 3, 'selected': True, 'text': "<p>You can use an Ajax request, but be sure to make it a synchronous request rather than an asychronous one.  Alternatively, simply save state whenever the user makes a change, this also protects the data if the user's browser crashes.</p>\n"}, {'answer_id': 73441, 'author': 'Adam Hopkinson', 'author_id': 12280, 'author_profile': 'https://Stackoverflow.com/users/12280', 'pm_score': 0, 'selected': False, 'text': '<p>You could also set a cookie using javascript on unload. I think the advantage ajax has over cookies is that you have the data available to you for reporting and the user (if logged in) can utilise the data across different machines.</p>\n\n<p>The disadvantage of using ajax is that it might slow down the actual closing of the browser window, which could be annoying if the server is slow to respond.</p>\n'}, {'answer_id': 73595, 'author': 'Alexandre Victoor', 'author_id': 11897, 'author_profile': 'https://Stackoverflow.com/users/11897', 'pm_score': 0, 'selected': False, 'text': '<p>It depends on how the user leaves the page.\nIf there is a \'logoff\' button in your GUI, you can trigger an ajax request when the user clicks on this button.\nOtherwise I do not think it is a good idea to make a request in the onUnload. As said earlier you would have to make a synchronous request...\nAn alternative to the cookie solution would be an hidden text field. This is a technique usually used by tools such as <a href="http://code.google.com/p/reallysimplehistory/" rel="nofollow noreferrer">RSH</a> that deal with history issues that come with ajax.</p>\n'}, {'answer_id': 76129, 'author': 'Douglas Mayle', 'author_id': 8458, 'author_profile': 'https://Stackoverflow.com/users/8458', 'pm_score': 1, 'selected': False, 'text': '<p>There\'s an answer above that says to use a synchronous ajax call, and that is the best case scenario.  The problem is that unload doesn\'t work everywhere.  If you look <a href="http://blog.rd2inc.com/archives/2005/05/04/unload-events-in-safari/" rel="nofollow noreferrer">here</a> you\'ll find some tricks to help you get unload events in safari...  You could also use Google Gears to save content user side for situations where the user will be coming back, but the only fully safe way to keep that information is to continuously send it as long as the user is on the page or making changes.</p>\n'}]
['https://Stackoverflow.com/questions/73335', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12559/']