6

SAPUI5 で REST サービスにアクセスしようとしています。jQuery を使用して GET リクエストを送信し、JSON 応答を期待していますが、取得できるのは空の JSON オブジェクトだけです。ただし、RESTClient でテストされた REST サービスは、正しい応答を返します。

ここに私がソファーを使用しているコードがあります:

意見

sap.ui.jsview("sapui5_test.SAPUI5_Test", { 

    getControllerName : function() {
        return "sapui5_test.SAPUI5_Test";
    },

    createContent : function(oController) {

    var text = new sap.ui.commons.TextField( {  
        width : "100%"  
    }); 

// arrange controls on the page with a matrix layout  
    var ml = new sap.ui.commons.layout.MatrixLayout( {  
        columns : 2,  
        layoutFixed : true,  
        width : "500px"  
    }); 

    ml.addRow(new sap.ui.commons.layout.MatrixLayoutRow( {  
        cells : [  
            new sap.ui.commons.layout.MatrixLayoutCell( {  
                content : [ text ]  
            })]  
    }));

    var model = oController.initTodoModel();

    text.setValue(model.getJSON());
    return [ ml ];
    }   



});

コントローラ

sap.ui.controller("sapui5_test.SAPUI5_Test", {

initTodoModel : function() {  
            var oModel = new sap.ui.model.json.JSONModel();
            var aData = jQuery.ajax({
                type : "GET",
                contentType : "application/json",
                url : "http://sapm04.ibsolution.local:50000/demo.sap.com~d337_resttest_web/rest/todo/init/",
                dataType : "json",
                success : function(data,textStatus, jqXHR) {
                    oModel.setData({modelData : data}); 
                    alert("success to post");
                }

            });

            return oModel;  
        }
}

});

index.html

<!DOCTYPE HTML>
<html>
<head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">

      <script src="resources/sap-ui-core.js"
            id="sap-ui-bootstrap"
              data-sap-ui-libs="sap.ui.commons,sap.ui.table,sap.ui.ux3"
            data-sap-ui-theme="sap_goldreflection">
    </script>
    <!-- add sap.ui.table,sap.ui.ux3 and/or other libraries to 'data-sap-ui-libs' if required -->

    <script>
            sap.ui.localResources("sapui5_test");
            var view = sap.ui.view({id:"idSAPUI5_Test1", viewName:"sapui5_test.SAPUI5_Test", type:sap.ui.core.mvc.ViewType.JS});
            view.placeAt("content");
    </script>

</head>
<body class="sapUiBody" role="application">
    <div id="content"></div>
</body>

既に述べたように、RESTClient で jQuery と同じ URL を実行すると、結果として入力された JSON オブジェクトが得られますが、UI5 ページの結果は空の JSON オブジェクト {} になります。

次の解決策も試しました。

var oModel = new sap.ui.model.json.JSONModel("http://sapm04.ibsolution.local:50000/demo.sap.com~d337_resttest_web/rest/todo/init/");

しかし、これは役に立ちませんでした。

4

1 に答える 1