Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep getting error: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 #3

Open
mastersoftwaremedia opened this issue Mar 28, 2017 · 12 comments

Comments

@mastersoftwaremedia
Copy link

Hi all,
I am having a trouble with this "Unexpected token < in JSON at position 0." I tried to utilize all the help I can get from online and still no luck. Anyone has an idea what is going on with this? I followed the code as it is and I am getting error. I am running crud at 3000 and backend at 8080 and they are both running without crushing on each other. I even checked the backend part and it is working fine. Since error occurred, the redux devtool extension or the state of fetching games is not in proper session. Thank you in advance!

json1
json2
json3
json4

@iqbalsafian
Copy link

you have to solved the first error first, which is undefined. i encountered the same issue though not to be exact.

@andrei-sheina
Copy link

@mastersoftwaremedia You probably have single quotes inside your options object in fetch method (in saveGame action in actions.js)
https://stackoverflow.com/questions/35852192/uncaught-in-promise-syntaxerror-unexpected-token-in-fetch-function

@mastersoftwaremedia
Copy link
Author

Thank you for the replies. I did look for the single quotes as you suggested, but found none. Does it work for you?

@iqbalsafian
Copy link

in chrome, go to redux tools and see what's the output, as mentioned by @andrei-sheina, the error might come from your actions.js, and you should check on your games reducers too.

@anonet1
Copy link

anonet1 commented Dec 6, 2017

I get same issue. were you able to solve it?

@arushi011
Copy link

I have a same issue. how to solve it?

@erichartline
Copy link

MongoDB syntax has changed since this video. Update your get request to this:

app.get("/api/games", (req, res) => {
    db
      .db("crudwithredux")
      .collection("games")
      .find({})
      .toArray((err, games) => {
        res.json({ games })
      })
  })

@jbdanquah
Copy link

I'm getting same since i made a change to my service worker script

@uncleejay
Copy link

Hello, I'm also getting the same error of "Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0" Here is my code...

getWeather = async (e) => {
e.preventDefault();
const city = e.target.elements.city.value;
const country = e.target.elements.country.value;
const api_call = await fetch(api.openweathermap.org/data/2.5/ weather?q=${city},${country}&appid=${API_KEY});
const data = await api_call.json();
console.log(data);
}

@wandumi
Copy link

wandumi commented Jul 16, 2019

The error comes when there is an error in the javascript code, I faced it once, my code was live this

const mymap = L.map('mine').setView([-26.2042,28.0473], 5);
// const langlong = L.marker([0, 0]).addTo(mymap);

    // saying this  tiles are comming from open sorce
    const attribution = 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors';
    const tileUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';

    //The create the tile of the map
    const tiles = L.tileLayer (tileUrl, { attribution });
    //add to the page
    tiles.addTo(mymap);

    const api_url = 'https:://www.mwpf.co.za/ecodashboardLive/public/livechart/map';

    
    async function getCordinates () {

        const response = await fetch(api_url);

        //Turn the data from the string to JSON
        const data = await response.json();

as you can see on the URL there are a double semi-colon, once I fixed it I solved it

@neelamchawla
Copy link

MongoDB syntax has changed since this video. Update your get request to this:

app.get("/api/games", (req, res) => {
    db
      .db("crudwithredux")
      .collection("games")
      .find({})
      .toArray((err, games) => {
        res.json({ games })
      })
  })

can you please share the complete page of server.js

@neelamchawla
Copy link

crud
I am getting nothing in games array... please help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants