Note that there are some explanatory texts on larger screens.

plurals
  1. POReading REST Service with SAPUI5
    primarykey
    data
    text
    <p>I am trying to access a REST Service with SAPUI5. I am sending a GET Request with the help of jQuery and expect a JSON respond, but all i get is an empty JSON Object. However the REST service tested with a RESTClient gives me the correct respond.</p> <p>Here is the code i am using sofar:</p> <h2>View</h2> <pre><code>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 ]; } }); </code></pre> <h2>Controller</h2> <pre><code>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; } } }); </code></pre> <h2>index.html</h2> <pre><code>&lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt; &lt;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"&gt; &lt;/script&gt; &lt;!-- add sap.ui.table,sap.ui.ux3 and/or other libraries to 'data-sap-ui-libs' if required --&gt; &lt;script&gt; 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"); &lt;/script&gt; &lt;/head&gt; &lt;body class="sapUiBody" role="application"&gt; &lt;div id="content"&gt;&lt;/div&gt; &lt;/body&gt; </code></pre> <p></p> <p>As already mentioned, when i run the same URL as in the jQuery in a RESTClient, i am getting a filled JSON Object as a result, however the result in the UI5 page is an empty JSON obejct {}.</p> <p>I also tried the following solution:</p> <pre><code>var oModel = new sap.ui.model.json.JSONModel("http://sapm04.ibsolution.local:50000/demo.sap.com~d337_resttest_web/rest/todo/init/"); </code></pre> <p>but this didn't help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload