cancel
Showing results for 
Search instead for 
Did you mean: 

How to submit multiple information in one request - having issues in passing data

former_member188685
Active Contributor
0 Kudos

Hello Everyone,

I tried creating a service that use Deep entity to post some data to SAP. That works well from test service option, but when i am trying to code from java script it is failing and getting" Http Request failed "

Following is the snippet i use for my testing to pass the data, is there anything wrong with my passing of parameters, please suggest.

var itemO = [{ID:24, Name:"xyz"}, {ID:45,Name:"tze"}];

var itemT = [{ID:24, Name:"xyz"}, {ID:45,Name:"tze"}];

var head = [{ID:24, Name1:"xyz", Name2:"abc"}];

var headerCont = [{Header:head, HeadItemT:itemT, HeadItemO:itemO}]

alert(requestUri);

var request = 

{ headers: {"X-Requested-With": "XMLHttpRequest", 

                "Accept": "application/atom+xml,application/atomsvc+xml,application/xml", 

                "Content-Type": "application/atom+xml", 

                "DataServiceVersion": "2.0" }, 

requestUri: requestUri, 

method: "POST", 

user: "user123", 

password: "welcome", 

data: headerCont }; 

// Send the request and define callback methods.

OData.read(

requestUri,

function (data) {

var html = "";

for (var i = 0; i < data.results.length; i++) {

alert("Hello" + data.results[i].ID;

}

document.getElementById("container").innerHTML = html;

},

function (err) {

alert("Error occurred " + err.message);

}

);

}

Accepted Solutions (1)

Accepted Solutions (1)

kammaje_cis
Active Contributor
0 Kudos

Vijay,

Problem seems to be in request body.

Can you please check this?

Krishna

former_member188685
Active Contributor
0 Kudos

Hi Krishna,

Thank you for the response, i am not using this in UI5 application. can this be done in javascript?

I tried adding it in javascript, is there anyway i can explore it? Any pointers on this will be highly appreciated.

Thanks

Vijay

kammaje_cis
Active Contributor
0 Kudos

If just javascript, then you would be using ajax calls. But still the requestbody remains the same. (As you saw in the thread I earlier mentioned).

In your above code, I do not see you issuing POST call.

former_member188685
Active Contributor
0 Kudos

var request =

{ headers: {"X-Requested-With": "XMLHttpRequest",

                "Accept": "application/atom+xml,application/atomsvc+xml,application/xml",

                "Content-Type": "application/atom+xml",

                "DataServiceVersion": "2.0" },

requestUri: requestUri,

method: "POST",

user: "user123",

password: "welcome",

data: headerCont };

Is it not sufficient to post or am i missing something. Also i followed the above thread and

not sure i can use this in my native application as it is not SAP UI5 based.

oModel = new sap.ui.model.odata.ODataModel('<URL>');


what will be the way to get the model instance if it is javascript, is there any place where i can refer the documentation for Ajax.  Thank you for the feedback.

ChandraMahajan
Active Contributor
0 Kudos

Hi Vijay,

you can refer Ajax documentation at  jQuery.post() | jQuery API Documentation and jQuery AJAX get() and post() Methods

Regards,

Chandra

former_member188685
Active Contributor
0 Kudos

Hi Chandra,

I was able to achieve with normal script, thank you for providing the response. Appreciate it.

Thanks

Vijay

former_member188685
Active Contributor
0 Kudos

Hi Krishna,

I did little tweaks to my code and able to perform what i want with simple script, really appreciate your inputs on this.

Thanks

Vijay

Answers (0)