相关疑难解决方法(0)

从jquery $ .ajax到angular $ http

我有这个jQuery代码,可以很好地交叉起源:

jQuery.ajax({
    url: "http://example.appspot.com/rest/app",
    type: "POST",
    data: JSON.stringify({"foo":"bar"}),
    dataType: "json",
    contentType: "application/json; charset=utf-8",
    success: function (response) {
        console.log("success");
    },
    error: function (response) {
        console.log("failed");
    }
});
Run Code Online (Sandbox Code Playgroud)

现在我想把它转换成Angular.js代码而没有任何成功:

$http({
    url: "http://example.appspot.com/rest/app",
    dataType: "json",
    method: "POST",
    data: JSON.stringify({"foo":"bar"}),
    headers: {
        "Content-Type": "application/json; charset=utf-8"
    }
}).success(function(response){
    $scope.response = response;
}).error(function(error){
    $scope.error = error;
});
Run Code Online (Sandbox Code Playgroud)

任何帮助赞赏.

ajax jquery cross-domain angularjs angular-http

121
推荐指数
1
解决办法
14万
查看次数

标签 统计

ajax ×1

angular-http ×1

angularjs ×1

cross-domain ×1

jquery ×1