var req = {
"RequestId": $scope.$parent.req_id,
"RequestDate": new Date(),
"RequestDetails": $scope.$parent.details
};
$scope.req_result = "test";
$.ajax({
type: "POST",
url: 'http://localhost:49358/api/myClasses/PostRequest',
data: JSON.stringify(req),
contentType: "application/json;charset=utf-8",
processData: true,
success: function (data, status, xhr) {
console.log("The result is : " + status);
$scope.req_result = "Post succeeded";
},
error: function (xhr) {
$scope.req_result = "ERROR: " + xhr.responseText
}
});
Run Code Online (Sandbox Code Playgroud)
范围变量$ scope.req_result未设置,因此当我尝试在html视图页面上显示它时:
<span>{{req_result}}</span>
Run Code Online (Sandbox Code Playgroud)
它显示默认值.不知何故ajax正在做什么是不知道角度