Hi,
I am using the following code to post my data back to OData interface. But I am unsuccessful in this. Even though I can do "GET" operation successfully,
I am failing in "POST".
What could be the case? I am posting my code below.
| function(){ |
| var id_var = sap.ui.getCore().byId("tid").getValue(); |
| var fname_var = sap.ui.getCore().byId("tfname").getValue(); |
| var lname_var = sap.ui.getCore().byId("tlname").getValue(); |
| var sapmod_var= sap.ui.getCore().byId("tsapmod").getValue(); |
| OData.request |
| ({ |
| requestUri: "http://server/sap/opu/odata/sap/ZUI5_KSS_MAC_SRV/Employees", |
| method: "GET", |
user: "xxxxxx",
password: "xxxxxxx",
| headers: | |
| { | |
| "X-Requested-With": "XMLHttpRequest", | |
| "Content-Type": "application/atom+xml", | |
| "DataServiceVersion": "2.0", | |
| "X-CSRF-Token":"Fetch" | |
| } | |
| }, | |
| function (data, response) | |
| { | |
| var header_xcsrf_token = response.headers['x-csrf-token']; | |
| OData.request | |
| ({ | |
| requestUri: "http://server/sap/opu/odata/sap/ZUI5_KSS_MAC_SRV/Employees", | |
| method: "POST", | |
| user: "xxxxxx", | |
| password: "xxxxxx", | |
| headers: { "X-Requested-With": "XMLHttpRequest", | |
| "Content-Type": "application/atom+xml", | |
| "DataServiceVersion": "2.0", | |
| "Accept": "application/atom+xml,application/atomsvc+xml,application/xml" | |
| }, | |
| data: | |
| { | |
| Id: id_var, | |
| Lname: lname_var, | |
| Fname: fname_var, | |
| Sapmod: sapmod_var | |
| } | |
| }, | |
| function (data, response) | |
| { | |
| document.location.reload(true); | |
| $("<div>Returned data " + window.JSON.stringify(data) + "</div>").appendTo($("#MessageDiv")); | |
| }, | |
| function (err) | |
| { | |
| $("<div>Returned error " + window.JSON.stringify(err.response) + "</div>").appendTo($("#MessageDiv")); | |
| alert("Error IN POST" + fname_var); | |
| } | |
| ); | |
| }, | |
| function (err) | |
| { | |
| var request = err.request; // the request that was sent. | |
| var response = err.response; // the response that was received. | |
| alert("Error in Get -- Request "+request+" Response "+response); | |
| alert("Error IN GET"); | |
| } | |
| ); |