Skip to content

Instantly share code, notes, and snippets.

@vojtajina
Created June 17, 2011 16:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vojtajina/1031783 to your computer and use it in GitHub Desktop.
Save vojtajina/1031783 to your computer and use it in GitHub Desktop.
Angular Simple POST using $xhr
<!DOCTYPE HTML>
<html xmlns:ng="http://code.angularjs.org/0.9.16/angular-0.9.16.min.js" ng:controller="Main">
<head>
<title>Simple Example of Angular's $xhr</title>
<script type="text/javascript" src="build/angular.js" ng:autobind></script>
<script type="text/javascript">
function Main($xhr){
var selft = this;
this.doRequest = function() {
$xhr('POST', 'url.php', 'data-content=233', function(code, response) {
self.response = response;
});
};
}
</script>
</head>
<body>
<a href ng:click="doRequest()">do POST request to url.php</a>
<div>{{response}}</div>
</body>
</html>
@AitorAlejandro
Copy link

Do you have version of this but doing it in a service??
Good one!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment