相关疑难解决方法(0)

无法在ajax调用中设置Angular范围变量

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正在做什么是不知道角度

ajax scope angularjs

0
推荐指数
1
解决办法
2020
查看次数

标签 统计

ajax ×1

angularjs ×1

scope ×1