von jquery $ .ajax zu eckigen $ http

Habe ich dieses Stück jQuery-code, der funktioniert einwandfrei Kreuz Herkunft:

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");
    }
});

Nun ich bin tring zu konvertieren, das auf Angular.js code ohne Erfolg:

$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;
});

Jede Hilfe dankbar.

InformationsquelleAutor der Frage Endless | 2012-08-26

Schreibe einen Kommentar