Reputation: 7932
We have installed Oracle APEX on our application server with ORDS and Weblogic app server. We are trying to use it to create simple ReST APIs that would fetch data from our database (11gR2). I have an HTML page developed which uses jqgrid
to convert the json
data from the ReST API to Tabular grid. The GET
request by jqgrid
to the URI is met with a 404 Resource not found
error.
The jqgrid
codes looks like this-
$("#jqGrid").jqGrid({
url: 'http://nsrmss01:9002/ords/oracle_retail_rest/comm/js',
mtype: 'GET',
datatype: 'json'
styleUI : 'Bootstrap',
colModel: [
{ label: 'Database', name: 'DBNAME', width: 100,editable: true },
{ label: 'SID', name: 'DBSID', width: 100,editable: true },
{ label: 'Port', name: 'DBPORT', width: 100,editable: true },
{ label: 'Last Refreshed', name: 'LASTREFRESHED', width: 150,editable: true ,
edittype : 'text',
editoptions: {
// dataInit is the client-side event that fires upon initializing the toolbar search field for a column
// use it to place a third party control to customize the toolbar
dataInit: function (element) {
$(element).datepicker({
autoclose: true,
format: 'dd-M-yyyy',
orientation : 'bottom'
});
}
}
},
{ label: 'Server Status', name: 'STATUS', width: 150,editable: true ,
edittype: "select",
editoptions: {
value:"AVAILABLE:Available;UNREACH:Unreachable;DOWN:Down"}
}
],
viewrecords: true,
height: 250,
loadonce: true,
rowNum: 20,
pager: "#jqGridPager"
});
The webpage has a simple jqgrid
table which should load the json
content which looks like below (3 rows for root dbdata
on the json
array)-
{
"dbdata": [
{
"dbname": "servdbp01",
"dbsid": "PROD",
"dbport": 1621,
"status": "AVAILABLE"
},
{
"dbname": "servdbd06",
"dbsid": "DEV01",
"dbport": 1621,
"lastrefreshed": "2015-01-01T08:00:00Z",
"status": "AVAILABLE"
},
{
"dbname": "servdbd06",
"dbsid": "SUP01",
"dbport": 1621,
"lastrefreshed": "2015-02-15T08:00:00Z",
"status": "AVAILABLE"
}
]
}
I have also tried jsonReader : {root: "dbdata"}
as option in the jqgrid
.
Browser debug shows this-
I am noticing that the content-type
in the response header sent by the service is text/html
as you can see below-
Should the content-type
be application/json
? and is that the issue? If so how do I change/configure ORDS to set the content-type? I am creating the ReST API using the APEX UI and have tested the API to be working through APEX test and SoapUI. I have looked here and else where about this issue but can't find anything relevant, so any help will be greatly appreciated.
Note: If I use datatype:'jsonstring'
then the error goes away, but then I am not sure how to convert the response back to a string. If I use $.getJSON()
to get the JSON
data i am getting a proper response back (see screenshot and code below). But I am just not sure how to use it in the JQGrid.
$.getJSON('http://nsrmss01:9002/ords/oracle_retail_rest/comm/js', function(data) {
console.log(data);
});
Upvotes: 1
Views: 1505
Reputation: 222007
The reason of the error 404 Resource not found could be the parameters, which will be sent to the server. You should add jqGrid option prmNames
to suppress sending of _search
, nd
and other:
prmNames: { nd: null, search: null, sort: null, order: null, rows: null, page: null }
Then you should fix the values of name
properties used in colModel
. JavaScript is case sensitive and you have to use, for example, name: 'dbname'
instead of name: 'DBNAME'
.
Finally I'd recommend you to use free jqGrid instead of commercial Guriddo jqGrid JS, which you currently used. Free jqGrid can be used under MIT or GPL v2 license completely free of charge. You need just change styleUI : 'Bootstrap'
parameter to guiStyle: "bootstrap"
. See the article for more details. Other optimizations can be done after your code will work.
Upvotes: 2