Javascript + jQuery: a crash course



A function is declared with the function() keyword

function doSomething(thing) {
    return console.log(thing.toUpperCase());

Function objects don’t even have to be declared with a name – you can write an anonymous function definition directly into the arguments of another

    // this code will be called in 5 seconds' time
}, 5000);

jQuery event methods


You must pass a function to the event

("p").click(function() {

jQuery callback functions


A callback function is executed after the current effect is completed.

Typical syntax: $(selector).hide(speed,callback);

    alert("The paragraph is now hidden");

jQuery and AJAX


Typical syntax: $.get/post(URL, params, callback);

    name: "John Doe",
    age: "42"
function(data, textStatus)
     alert("Response from server: " + data);

The first parameter of the callback function is the content of the page requested. Since most of times this content is json stuff, I could access its fields with and alike.

The second parameter to the callback function is the request exit status.

If I use get instead of post, it would perform a GET request like test_get.php?name=John Doe&age=42