Writing a simple delay is quite simple in Javascript.

I’m not a Javascript guru…. or any other type of guru. Often times while working on something I just come across a certain scenario that needs a tweek or a small problem to solve.

So while writing some code to create on inline editing (in a data grid for example) I had some JS functions that would load my form to replace the data, submit the form in the background (POST HTTP request…). Problem was when the data grid’s cell would reload it would actually reload the old data. The update was taking just a touch longer then the function that was requesting the row’s data.

Every thing was firing in the proper order. I just needed to delay the function that would reload the grid’s row.

At first I thought I could do something like this:
$(“#divToReload”).delay(500).load(reloadURL);

I figured the delay should work. But I believe, the delay function is better suited for animations… fades and such.
(Also, I am using jQuery)

So I set a timeout function to initiate the jQuery function which worked perfectly.
setTimeout(function() {$(“#divToReload”).load(reloadURL);},500);