Created
September 13, 2011 16:14
-
-
Save brianyang/1214233 to your computer and use it in GitHub Desktop.
rails backbone - rest api - ajax function
This file contains 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
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