0
I’m having a problem with Javascript Fetch
let url = "https://www.teste.com.br/ws"
fetch(url,{
mode: 'no-cors',
method: 'GET',
headers: {'Accept': 'application/json','Content-Type': 'application/json'}
}).then(function(response){
response.json().then(function(data) {
console.log(data);
})
}).catch(function(error){
console.log(error);
});
In the Console appears the error ( Uncaught (in Promise) Syntaxerror: Unexpected end of input at fetch.js:10 which is the line " Response.json(). then(Function(data) { " Can someone help me solve this ?
Thanks.
There are some syntax errors in the code, for example
let url = "let url = "https://www.teste.com.br/ws"
– Sam
Here too:
});"
– Sam
tidied up the issue of Let url. This happened because I copied wrong.
– Rodrigo Pereira de Freitas
The problem should be in the return, because the code itself is working normal.
– Sam
on the site, I wrote some website because the webservice is from the company.
– Rodrigo Pereira de Freitas
But there was still a mistake on the line
});"
(wrong double quotes).– Sam
Oh yes... I tested here and even with any URL does not present the mentioned error.
– Sam
because it is expensive, it works even but does not return me the json
– Rodrigo Pereira de Freitas
this error appears Uncaught (in Promise) Syntaxerror: Unexpected end of input at fetch.js:10
– Rodrigo Pereira de Freitas
You want to make 2 fetchs?
– Sam
I already removed the duplicate
– Rodrigo Pereira de Freitas
must be something else, because the code does not return any error.
– Sam
Take a look at this link and opens the console. See tb in the source code the indented script straight. It’s all blz.
– Sam
Remove
mode: 'no-cors'
options and see what happens!– NoobSaibot