Testing

Note! These testing examples are very simple and not suited to be used in any production environment.

Using Javascript XMLHttpRequest

// Build the command
var command = 	{
		Type: "SELECT",
		List: "Tasks"
}

// Send the command
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","/camelot/jsonapi.svc/Items?command="+JSON.stringify(command) ,false);
xmlhttp.setRequestHeader("Content-type","application/json");
xmlhttp.send();

// Decode and store the result in a variable
var result = JSON.parse(JSON.parse(xmlhttp.responseText).d);

Using jQuery Ajax

// Build the command
var command = 	{
		Type: "SELECT",
		List: "Tasks"
}

// Declare outside of the ajax call to be able to read the data for testing
var result;

// Send the command
$.ajax({
	type: "GET",
	contentType: "application/json",
	data: { command: JSON.stringify(command)},
	url: "/camelot/jsonapi.svc/Items",
	success: function (data) {
		// Decode and store the result in a variable
		result = $.parseJSON(data.d);
		console.log("Successfully executed the command, please check the 'result' variable.");
	},
	error: function (xhr, textStatus, errorThrown) {
		console.log(errorThrown);
	}
});

Last edited Jan 24, 2013 at 4:03 PM by Bendsoft, version 3

Comments

No comments yet.