您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

从jquery $ .ajax到angular $ http

从jquery $ .ajax到angular $ http

AngularJS调用$ http的方式如下所示:

$http({
    url: "http://example.appspot.com/rest/app",
    method: "POST",
    data: {"foo":"bar"}
}).then(function successCallback(response) {
        // this callback will be called asynchronously
        // when the response is available
        $scope.data = response.data;
    }, function errorCallback(response) {
        // called asynchronously if an error occurs
        // or server returns response with an error status.
        $scope.error = response.statusText;
});

或者可以使用快捷方式将其编写得更加简单:

$http.post("http://example.appspot.com/rest/app", {"foo":"bar"})
.then(successCallback, errorCallback);

有很多事情要注意:

上面只是一个简单的示例和一些指针,请务必查看AngularJS文档以获取更多信息:http: //docs.angularjs.org/api/ng.$http

JS 2022/1/1 18:14:03 有616人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶