Monthly Archives: May 2010

setInterval vs. setTimeout in Javascript

Recently i ran into a strange javascript behavior.

I tried to periodically update a certain container on a page.

At first i tried it with:

foobar = function(){
  $('#my_div').load('myurl');
  setTimeout('foobar',10000);
};
setTimeout('foobar',10000);

I found out, its working correctly (it updates the div every 10 seconds), but i detaches the old DOM (the whole site), and adds the new Response-DOM as new Content, thats very strange because if you click another page, and then use the Browser-Back Button, there are no styles, or Javascript. So very very very bad, i didn’t get the clue what went wrong.

Then i refactored it bit, so it looks like this:

foobar = function(){
  $('#my_div').load('myurl');
};
setInterval('foobar',10000);

And voila, its working as expected. It updates the div correctly, and leaves the rest of the DOM untouched.
Dont know whats the difference between those 2 examples?!

reset of the digital kaoz

After a big bad Server-Crash, i had to reset my whole server :( . Good that i was able to backup everything i need.

The first steps were setting up all the system services again. Thanks to ubuntu that i love so much, and know so well :) .

The first and easiest way to be “online” again was to setup a wordpress blog, and voila here it is.

The installation and configuration is easy, and the system works perfect. Now i have to customize it. WordPress is a bit new for me, and it seems, it is not very organized and straight forward like the symfony framework.

After seeing some code, i hope i dont have to iteract that much with the codebase :) but the interface is very nifty, and easy to use.

I think i will stay at wordpress for the blogging software, so i have to work on my symfony sfWordpressPlugin again.

There is still so much todo, configuring wordpress, setting up my svn again, setting up my development sites again…