Joe's Blog

line

A blog by Joe Billman about programming, and other stuff

line

Archive for the ‘JQuery’ Category

RESTful calls via JQuery

Posted on: November 5th, 2014 by Joe

line No Comments

I created a post showing hoe to make RESTful calls with plain vanilla JavaScript and wanted to show how to do the same thing using JQuery. So here it is:

RESTService.prototype.doPost = function(url, data, successHandler, errorHandler)
{
    $.ajax(
    {
	data: JSON.stringify(data),
	dataType: 'json',
	type: 'POST',
	url: url,
	beforeSend: function(request)
	{
	    request.setRequestHeader('accept', 'application/json');
	    request.setRequestHeader('content-type', 'application/json;charset=UTF-8');
	},
	success: function(response)
	{
            successHandler(response);
    	},
	error: function(response)
        {
            errorHandler(response);
	}
    });
};


Warning: Use of undefined constant Y - assumed 'Y' (this will throw an Error in a future version of PHP) in /homepages/16/d145171736/htdocs/php/footer.php on line 1