Ich habe gerade angefangen Angular.js zu lernen. Wie schreibe ich den folgenden Code in Angular.js neu?
var postData = "<RequestInfo> "
+ "<Event>GetPersons</Event> "
+ "</RequestInfo>";
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState == 4 || req.readyState == "complete") {
if (req.status == 200) {
console.log(req.responseText);
}
}
};
try {
req.open('POST', 'http://samedomain.com/GetPersons', false);
req.send(postData);
}
catch (e) {
console.log(e);
}
Hier ist, was ich bisher haben -
function TestController($scope) {
$scope.persons = $http({
url: 'http://samedomain.com/GetPersons',
method: "POST",
data: postData,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function (data, status, headers, config) {
$scope.data = data; // how do pass this to $scope.persons?
}).error(function (data, status, headers, config) {
$scope.status = status;
});
}
html
<div ng-controller="TestController">
<li ng-repeat="person in persons">{{person.name}}</li>
</div>
Bin ich in die richtige Richtung?
Thank you very much. Es hat perfekt funktioniert. – tempid
Danke, ich habe so viele Lösungen ausprobiert aber Kopfzeilen: '{'Content-Type': 'application/x-www-form-urlencoded'}' hat den Trick gemacht –
Bitte beachten Sie, dass die 'success' und' error' Funktionen haben jetzt veraltet. – Ali