andrewlocatelliwoodcock

Thoughts on Software

Posts Tagged ‘JavaScript

How websites work, an introductory tech presentation

with 6 comments

I recently gave a tech intro session entitled “How websites work”, a kind of 101 session on the basics of web technology. The session references PHP specifically as that’s the development language at my current employer but most server-side languages work in a similar manner.

Readers of this blog will mostly know this stuff anyway but I was asked to make it available for download so here it is: enjoy!

How Websites Work

 

Written by andrewlocatelliwoodcock

June 11, 2012 at 22:28

Posted in PHP, Talks, Websites

Tagged with , , , ,

AJAX post from window unload event not reaching controller

with one comment

I hit an interesting problem today: an AJAX post sent using jQuery’s $.ajax method was failing to reach the controller action method but only intermittently. The kind of problem guaranteed to drive me nuts until I’ve figured it out …

What was happening was that I was building a queue that I then wanted to post to a controller once the queue reached a certain size or once the user navigated away from the current page. The page navigation feature was implemented using jQuery’s window unload event:

$(window).unload …

The postQueue function was always being hit whether it was called from the queue manager or the unload event but it was only managing to correctly post to the controller if called from the queue manager … a half day’s work was fast turning into one and a half days …

Turns out that the issue was that you cannot post asynchronously from a function called from the unload event because there is no longer a callback function in scope even if you are not actually using a callback handler …

The solution is to make sure that you only post synchronously from within the unload event by setting the async property of the ajax object to false.

Written by andrewlocatelliwoodcock

May 13, 2011 at 17:30

Posted in ASP.Net MVC, javascript

Tagged with , ,