Skip to content

Instantly share code, notes, and snippets.

@colonelmac
Created September 7, 2012 03:46
Show Gist options
  • Save colonelmac/3662893 to your computer and use it in GitHub Desktop.
Save colonelmac/3662893 to your computer and use it in GitHub Desktop.
Testing REST API with jQuery
$(document).ready(function () {
// use JSON to structure your parameter
// { derp: 1, herp: 'hello' } equivalent to ?derp=1&herp=hello
var params = { };
function onsuccess(data, status, jqxhr) {
// data will be a native javascript object
console.log(data);
}
// modify 'type' to select between GET, POST, DELETE, PUT
$.ajax({ url: 'http://herp.org/api/derp',
data: params,
datatType: 'json',
type: 'GET'
success: onsuccess
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment