Created
September 7, 2012 03:46
-
-
Save colonelmac/3662893 to your computer and use it in GitHub Desktop.
Testing REST API with jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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