Fetch and Json Problem in Jquery Javascript

Asked

Viewed 139 times

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"

  • Here too: });"

  • tidied up the issue of Let url. This happened because I copied wrong.

  • The problem should be in the return, because the code itself is working normal.

  • on the site, I wrote some website because the webservice is from the company.

  • But there was still a mistake on the line });" (wrong double quotes).

  • Oh yes... I tested here and even with any URL does not present the mentioned error.

  • because it is expensive, it works even but does not return me the json

  • this error appears Uncaught (in Promise) Syntaxerror: Unexpected end of input at fetch.js:10

  • You want to make 2 fetchs?

  • I already removed the duplicate

  • must be something else, because the code does not return any error.

  • Take a look at this link and opens the console. See tb in the source code the indented script straight. It’s all blz.

  • Remove mode: 'no-cors' options and see what happens!

Show 9 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.