Javascript: difference between a statement and an expression?

Are all statements also expressions? “Wherever JavaScript expects a statement, you can also write an expression. Such a statement is called an expression statement. The reverse does not hold: you cannot write a statement where JavaScript expects an expression. For example, an if statement cannot become the argument of a function.” This is comes from … Read more

Simple pagination in javascript

I’ll address any questions you have… but here is an improved pattern you should follow to reduce code duplication. As a sidenote though, you should consider not doing pagination on client-side. Since if you have a huge dataset, it would mean you need to download all the data before your page loads. Better to implement … Read more

anchor jumping by using javascript

You can get the coordinate of the target element and set the scroll position to it. But this is so complicated. Here is a lazier way to do that: This uses replaceState to manipulate the url. If you also want support for IE, then you will have to do it the complicated way: Demo: http://jsfiddle.net/DerekL/rEpPA/Another … Read more

Using setTimeout on promise chain

To keep the promise chain going, you can’t use setTimeout() the way you did because you aren’t returning a promise from the .then() handler – you’re returning it from the setTimeout() callback which does you no good. Instead, you can make a simple little delay function like this: And, then use it like this: Here … Read more

How can I use jQuery to run MySQL queries?

You can use ajax to call a server page (PHP / ASP /ASP.NET/JSP ) and in that server page you can execute a query. http://api.jquery.com/jQuery.ajax/ HTML Javascript This code will be excuted when user clicks on the button with the id “btnVote”. The below script is making use of the “ajax” function written in the … Read more