Last active
September 20, 2015 19:05
-
-
Save keyserfaty/536ddbb02b7c4b61a28c to your computer and use it in GitHub Desktop.
$http.post Angular
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
$http.post(url, data, { | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' | |
}, | |
transformRequest: function(data) { | |
return $.param(data); | |
} | |
}). | |
success(function(data, status, headers, config) { | |
if (data.error) { | |
alert(data.error); | |
_trackAddError(data.error); | |
} else { | |
$location.path('/posts'); | |
} | |
}). | |
error(function(data, status, headers, config) { | |
console.log('error adding post'); | |
_trackAddError(data.error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment