E-JAMBON bio photo

E-JAMBON

Ce qui se conçoit bien s'exprime clairement.

Email Twitter Github

This is a memo post. It should fall under the wiki, but for some reasons, I find it more comfortable to write in my regular editor. Thanks again Jekyll. What a relief. So flexible.

Ajax call

Simple ajax call on click of a button. the success indicates the function used on success.

$(".execution #exampleOne").on('click', 'button', function(){
	$.ajax( 'http://links.e-jambon.com', {
		success: function(response){  /* do something with the response */ },
		data: '?requestparameter=value'
	});

});

The idea being to call a server and getting a response, ajax can of course do way more. settings object can have pretty much all the options a request needs to go through. Check the API references here

For reference, my best move so far to understand what’s going on under the hood has been spending time trying to read the damn HTTP RFC. I did not read all of it, but most of it. And it is worth it, although it admitedly is boring. I even come back to reading pieces once in a while.

So there is another “shortcut” method to get info from a server using jquery : the “GET” method. Example :

$.get( "/test/user", { name: "e-jambon" } ); //random example.

Of course, there is $.post method as well.

$.post( "/test/login", {name: "e-jambon", password: "MS-P4ssw0rd"} );

Those methods also work as described in the http protocol.
Since HTTP is a REST protocol, I have of course been looking into the other methods : PUT and DELETE.
Surprisingly enough, there is no $.delete nor $.put method.
It looks like one must use the $.ajax and specify the method: to use.