Remchi / crud-with-redux

91 stars 36 forks source link

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

Open mastersoftwaremedia opened 7 years ago

mastersoftwaremedia commented 7 years ago

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 commented 7 years ago

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

andrei-sheina commented 7 years ago

@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 commented 7 years ago

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

iqbalsafian commented 7 years ago

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 commented 6 years ago

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

arushi011 commented 6 years ago

I have a same issue. how to solve it?

erichartline commented 6 years ago

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 commented 6 years ago

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

uncleejay commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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 commented 4 years ago

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