cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Fetch API throwing error called "SyntaxError: Unexpected token '<', "

0 Likes
11,288

HI,

The same code is working fine in SAP WEB IDE. and I'm able to call it Fetch API with method Post Successfully.

Now I have deployed Fiori app from SAP WEB IDE to S4 Hana Cloud. Now Iam getting error for fetch API in console is

"SyntaxError: Unexpected token '<', "<html><hea"... is not valid JSON"

Network Tab Response in debugger mode is

<html><head><title>Error report</title></head><body><h1>HTTP Status 500 - An internal application error occurred.

Request: -------------------</h1></body></html>

Could you please let me know, same code working fine in SAP WEB IDE and but not working after deployed to S4 Hana cloud?

How to resolve this issue?

PFB ,

const perform3 = (x) => {

return fetch(api, {

method: 'post',

headers: {

"X-Requested-With": 'XMLHttpRequest',

"Content-Type": 'application/json',

"X-CSRF-Token": CSRFToken,

"Accept": 'application/json',

},

body: JSON.stringify(x)

})

.then((res) => res.json())

.then((data) => {

console.log("Success:", data);

MessageArray.push({

Data: data

})

.catch((error) => console.log(error))

}

View Entire Topic
leonikussmaul
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Madhava,

Are you sending the payload in XML format? Since you have defined the request header Content-Type as "application/json", it would expect the payload in json format and throw an error as soon as the XML payload begins with the opening tag "<".

Try changing the Content-Type header to "text/xml" instead if your payload is in XML format.

0 Likes

HI

FYI

The same code is working fine in SAP WEB IDE. and I'm able to call it Fetch API with method Post Successfully.

Now I have deployed Fiori app from SAP WEB IDE to S4 Hana Cloud. Now Iam getting error for fetch API in console is

"SyntaxError: Unexpected token '<', "<html><hea"... is not valid JSON"

Also, I have sent data in json format. Still iam getting same error

Any way i have used APi in promises. Its working as expected.