Skip to content

Instantly share code, notes, and snippets.

@brianyang
Created September 13, 2011 16:14
Show Gist options
  • Save brianyang/1214233 to your computer and use it in GitHub Desktop.
Save brianyang/1214233 to your computer and use it in GitHub Desktop.
rails backbone - rest api - ajax function
function getData(){
$.get('http://localhost:3000/posts.json');
}
function postData(){
var url ='http://localhost:3000/posts';
var data = {title:"asdf",content:"asdf"};
$.ajax({
type: "POST",
url: url,
data: {"post":{"title":"foo","content":"bar"}},
success: function() {
// stub
alert('done')
},
dataType: 'json'
});
}
function deleteData(){
var url = 'http://localhost:3000/posts/70';
var success = function(){
alert('foo');
}
$.ajax({
url: url,
type:'DELETE',
success:success
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment