OData 读取回调未在 UI5 控制器中触发

OData Read-Callbacks not triggered in UI5 controller

我需要从 SAPUI5 手动调用 OData 到我的 SAP 网关(没有数据绑定)。

为此,我使用了以下代码:

oModel.read("/ZTestSet"),  
    null,null,false, function(oData, oResponse){
       alert("success");
    },
    function(oError ){
       alert("error");
} 

我已经在SAP系统上调试过了。我接到了电话,并在 et_entityset 中填写了所需的数据。

问题是,没有函数会被触发作为回调。既没有成功也没有错误(我在网关或其他人上找不到任何错误)。

浏览器开发者工具中的响应:

HEADERS:
     
Request Method:GET
Status Code:200 OK
     
RESPONSE HEADERS:
cache-control:no-store, no-cache
Connection:keep-alive
content-encoding:gzip
Content-Length:827
Content-Type:application/atom+xml; charset=utf-8
dataserviceversion:2.0
Date:Tue, 05 Apr 2016 12:08:34 GMT
Proxy-Connection:keep-alive
sap-metadata-last-modified:Tue, 05 Apr 2016 10:06:59 GMT

REQUEST HEADERS:
Accept:application/atom+xml,application/atomsvc+xml,application/xml
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US
Cache-Control:no-cache
DataServiceVersion:2.0

RESPONSE:
<feed xmlns="http://www.w3.org/2005/Atom" 
 xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="<<ADDRESS>>">
  <id><<ADDRESS>></id>
  <title type="text"><<FUNCTION>></title>
  <updated>2016-04-05T12:08:34Z</updated>
  <author>
    <name />
  </author>
  <<LIST OF ENTRIES>>
</feed>

看起来调用成功了。

将下面的调试器行放在成功和错误调用中,看看它是否在浏览器中触发。 oModel.read 是一个异步调用,意味着它不等待响应,只有在收到来自服务器的响应后才会触发成功或错误方法。因此,如果您正在等待,那么它可能看起来什么都没发生。

              debugger;

多么愚蠢的错误。

我在 URL 之后关闭了括号。 应该在最后一个参数后自然关闭。在我的例子中,在错误函数之后。

正确的代码:

oModel.read("/ZTestSet", null, null, false, function(oData, oResponse) {
  alert("success");
}, function(oError){
  alert("error");
});