Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript BreezeJs,saveChanges()-未捕获类型错误:无法读取属性';状态文本';未定义的_Javascript_Angularjs_Odata_Breeze_Sap Gateway - Fatal编程技术网

Javascript BreezeJs,saveChanges()-未捕获类型错误:无法读取属性';状态文本';未定义的

Javascript BreezeJs,saveChanges()-未捕获类型错误:无法读取属性';状态文本';未定义的,javascript,angularjs,odata,breeze,sap-gateway,Javascript,Angularjs,Odata,Breeze,Sap Gateway,我使用BreezeJS和Angular来使用SAP Netweaver网关系统提供的Restful OData服务中的数据。应用程序当前正在正确地从服务读取数据,包括元数据,并按预期将所有数据保存在EntityManager中 但是,当我更改其中一个实体的状态并执行saveChanges()时,不会调用成功或失败回调,而是显示控制台错误 Uncaught TypeError: Cannot read property 'statusText' of undefined 调用save的代码如下

我使用BreezeJS和Angular来使用SAP Netweaver网关系统提供的Restful OData服务中的数据。应用程序当前正在正确地从服务读取数据,包括元数据,并按预期将所有数据保存在EntityManager中

但是,当我更改其中一个实体的状态并执行saveChanges()时,不会调用成功或失败回调,而是显示控制台错误

Uncaught TypeError: Cannot read property 'statusText' of undefined 
调用save的代码如下所示

$scope.doSave = function(){
    $scope.purchases[0].Requester = "Dave" ;
        $scope.items[0].Description = "New Description";
        if (!$scope._isSaving)
        {
            console.log("Saving!");
            $scope._isSaving = true;
            manager.saveChanges().then(function(data){
                console.log("Saved");
                console.log(data);
                $scope._isSaving = false;
            }, function(error){
                console.log(error); 
                $scope._isSaving = false;});
        }
}
其中,经理是标准的Breeze实体经理

该代码在服务器上被缩小,因此很难调试通过,但这是在一个核心breeze库中抛出的

客户机正在向服务器执行$batch POST请求,而服务器正在以一个已接受的消息进行响应,如下所示

--0DD0586DB234C0A3D0D530A25CD1C8400
Content-Type: multipart/mixed; boundary=0DD0586DB234C0A3D0D530A25CD1C8401
Content-Length:       519

--0DD0586DB234C0A3D0D530A25CD1C8401
Content-Type: application/http
Content-Length: 111
content-transfer-encoding: binary

HTTP/1.1 204 No Content
Content-Type: text/html
Content-Length: 0
dataserviceversion: 2.0
content-id: 1


--0DD0586DB234C0A3D0D530A25CD1C8401
Content-Type: application/http
Content-Length: 111
content-transfer-encoding: binary

HTTP/1.1 204 No Content
Content-Type: text/html
Content-Length: 0
dataserviceversion: 2.0
content-id: 2


--0DD0586DB234C0A3D0D530A25CD1C8401--

--0DD0586DB234C0A3D0D530A25CD1C8400--

我希望这是这里的人以前见过的东西

最后,这证明是SAP Netweaver网关处理OData的一个怪癖。它在不应该发送头的时候发送头,并将“Content-ID”头作为Content-ID发送

为了解决这些问题,我不得不在datajs1.1.1中的readBatch方法中添加行

if (response.statusCode >= 200 && response.statusCode <= 299) {
     partHandler(context.handlerContext).read(response,   context.handlerContext);
} else {
     // Keep track of failed responses and continue processing the batch.
     response = { message: "HTTP request failed", response: response };
}


这解决了问题,并确保正确处理了响应。

您是否检查代码中某个位置的statusText值?您应该显示breeze manager如何获取实体,如何更改实体HI,感谢您的评论。自从我发布这篇文章以来,我已经设法调试了更多的方法,问题似乎是返回的数据带有“Content-Type:text/html”以及204 No-Content头。DataJS将其解释为有数据,因为它有一个内容类型,因此导致它尝试读取数据,然后失败,因为它没有文本/html类型的处理程序,这将返回到Breeze,而不是它期望的响应对象insead接收到一个字符串“此数据没有处理程序”,它尝试检查此的statusText,但失败。不太确定如何修复此问题,因为我无法在此处更改服务器行为。
if (response.statusCode >= 200 && response.statusCode <= 299) {
    if (response.statusCode != 204) 
        partHandler(context.handlerContext).read(response,   context.handlerContext);
} else {
     // Keep track of failed responses and continue processing the batch.
     response = { message: "HTTP request failed", response: response };
}
var contentId = cr.headers["Content-ID"];
var contentId = cr.headers["content-id"];