jquery - $.ajax like function for React js and Angular js? -
how post data using react , angular?
is there has function $.ajax
react , angular?
i mean need post function react , angular
$.ajax{ url:"test.php", type:"post", cache:false, success... etc.
the angularjs way of calling $http like:
$http({ url: "http://example.appspot.com/rest/app", method: "post", data: {"foo":"bar"} }).success(function(data, status, headers, config) { $scope.data = data; }).error(function(data, status, headers, config) { $scope.status = status; });
or written simpler using shortcut methods:
$http.post("http://example.appspot.com/rest/app", {"foo":"bar"}) .success(function(data, status, headers, config) { $scope.data = data; }).error(function(data, status, headers, config) { $scope.status = status; });
there number of things notice:
angularjs version more concise (especially using .post() method)
angularjs take care of converting js objects json string , setting headers (those customizable)
callback functions named success
, error
respectively (also please note parameters of each callback)
the above quick example , pointers, sure check angularjs documentation more: http://docs.angularjs.org/api/ng.$http
from: from jquery $.ajax angular $http
for react: http://andrewhfarmer.com/react-ajax-best-practices/
Comments
Post a Comment