jQuery addClass example

Change class name on click in jQuery

by dont_panic

JavaScript

function getData (url, privateToken) {
	console.log('getData firing ...');
    return $.ajax({
        'url': url,
        // JSFiddle /echo/json/ requires POST
        'method': 'POST',
        'headers': {
            'PRIVATE-TOKEN': privateToken
        },
        // Dummy data, this is what JSFiddle's /echo/json/ will return as response
        'data': {
            json:'{"foo":"bar","colour":"blue", "size": 4}'
        }
    });
}


$(document).ready(function(){
	// JSFiddle uses /echo/json/ to simulate AJAX requests, use that here
    console.log('Calling getData ...');
	var $ajax = getData("/echo/json/", "token");
    console.log('We have returned, but the AJAX request is still in progress, and we have no response yet ...');
	$ajax.always(function(response, textStatus, jqXHR) {
    	console.log('Now the request is done, and we have a response:');
	    console.dir(response);
        console.log('response colour:', response.colour);
    });
});