OJET Create/Insert/POST Records into Database Using the $.ajax JavaScript Command JSON.stringify
How to Create/Insert/POST Records OJET into Database Using the $.ajax JavaScript Command OJET JSON.stringify
You can Generate the REST using the ADF, but this may work using the POSTMAN, but while using it in Netbeans it may not work, in that case make sure you are using the below two CROS Origin Jar Library file in your ADF Project.
cors-filter-2.6.jar
java-property-utils-1.9.1.jar
Also include the below code in web.xml in the ADF Project.
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, POST, HEAD, PUT, PATCH, DELETE</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Once above two steps are done, RUN the ADF REST Application which will provide the REST web Service/end point as below example.
http://13.0.0.1:7101/ExposeREST-RESTWebService-context-root/rest/1/dept
In my Case I hard Code the JSON Payload.
Also Make sure to Use JSON.stringify while loading the JSON Data.
--------------------------------------------------------------------------------------------------------------------------
Customer.JS
--------------------------------------------------------------------------------------------------------------------------
define(['knockout', 'appController', 'ojs/ojmodule-element-utils', 'accUtils',
'ojs/ojcore','ojs/ojconverterutils-i18n','ojs/ojarraydataprovider', 'jquery',
'text!data/Deptment.json','ojs/ojbootstrap','ojs/ojknockout',
'ojs/ojtable','ojs/ojdatetimepicker','ojs/ojarraytabledatasource','promise'],
function(ko, app, moduleUtils, accUtils,oj,ConverterUtilsI18n,ArrayDataProvider,$,jsonfile,Bootstrap) {
function DashboardViewModel() {
var self = this;
self.submitBt = function () {
alert(self.user() +" - " +self.password());
$.ajax({
url: "http://13.0.0.1:7101/ExposeREST-RESTWebService-context-root/rest/1/dept",
data: JSON.stringify({"DepartmentId": 15,"DepartmentName": "Netting","ManagerId": 201,"LocationId": 1800}),
type: "POST",
contentType: "application/json",
//contentType: 'application/vnd.oracle.adf.action+json',
dataType: 'json',
success: function (data, textStatus, jqXHR) {
var x = data;},
error: function (jqXHR, textStatus, errorThrown) {
alert("401 Unauthorized");
}
});
return true;
}
}
return DashboardViewModel;
}
);
--------------------------------------------------------------------------------------------------------------------------
Customer.html
--------------------------------------------------------------------------------------------------------------------------
When Click on the Login button, it will post the JSON Payload Record into the database.
<input id="submit" type="submit" data-bind="click: submitBt,
ojComponent: {component: 'ojButton', label: 'Login'}"/>
As a Result of the above code, the records are stored into the database as below screen shots.
Comments
Post a Comment