Hi Parag,
If you want response always in JSON format you can use JSONModel as below
var oLine_Model = new sap.ui.model.json.JSONModel();
See below example code
getOrderDetails: function(oEvent) {
var oLine_Model = new sap.ui.model.json.JSONModel();
//Make model global by setModel so that it can be accessed in other controllers also.
sap.ui.getCore().setModel(oLine_Model, "Order_Model");
//Navigate to other View
this.router.navTo("order_details");
}
And in Component.JS file you can define your Service setting like below
config: {
viewType: "JS",
viewPath: "view",
targetControl: "<your app name>", //Name of Split App given in App.view.js file
clearTarget: false,
transition: "slide",
"serviceConfig": {
"name": "<your service name created in Gateway>",
"serviceUrl": "/sap/opu/odata/sap/<your service name created in Gateway>/"
}
},
Just to Understand how this works :
Another way to get response in JSON you can have AJAX call as below
jQuery.ajax({
url: "/path/to/data.json", // for different servers cross-domain restrictions need to be handled
dataType: "json",
success: function(data, textStatus, jqXHR) { // callback called when data is received
oModel.setData({data: data}); // fill the received data into the JSONModel
},
error: function(jqXHR, textStatus, errorThrown) {
alert("error occurred");
}
});
You can put below line in Component.JS once and use the object name to setModel.
var oLine_Model = new sap.ui.model.json.JSONModel(); --> in Component.JS
sap.ui.getCore().setModel(oLine_Model, "Order_Model"); --> In your code
If you are running service dirlectly from SEGW then you have to provide $format=JSON in Query string then only you will get response in JSON format.
But in code you can use above suggested things to get response in JSON format always.
Hope this will help you.
Thanks-
Abhishek