Today at work I needed to do some Ajax calls to update some information in the database and pull the most recent results for the administration side of the project. I was stumped for about 10 minutes while trying to figure out why my button would not change back to its original state after displaying “updated.” It turns out that when you call a function using ‘setTimeout’ and you do not wrap the function in quotation marks, the function will be triggered immediately.
1 2 3 4 5 | //function is triggered immediately. setTimeout(updateRecord(), 500); //function is triggered after the set time. setTimeout("updateRecord()", 500); |
This immediate triggering makes sense when you think about how the triggering within the parameters operates but it got me all the same.
Related posts: