crud-with-redux icon indicating copy to clipboard operation
crud-with-redux copied to clipboard

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

Open mastersoftwaremedia opened this issue 7 years ago • 12 comments

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

mastersoftwaremedia avatar Mar 28 '17 05:03 mastersoftwaremedia

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

iqbalsafian avatar May 03 '17 02:05 iqbalsafian

@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

andrei-sheina avatar May 28 '17 06:05 andrei-sheina

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

mastersoftwaremedia avatar May 31 '17 20:05 mastersoftwaremedia

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.

iqbalsafian avatar Jun 01 '17 23:06 iqbalsafian

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

anonet1 avatar Dec 06 '17 21:12 anonet1

I have a same issue. how to solve it?

arushi011 avatar Jan 14 '18 19:01 arushi011

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 })
      })
  })

erichartline avatar Feb 11 '18 02:02 erichartline

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

jbdanquah avatar Jul 02 '18 21:07 jbdanquah

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); }

uncleejay avatar Feb 23 '19 17:02 uncleejay

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

wandumi avatar Jul 16 '19 14:07 wandumi

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 avatar Jul 11 '20 13:07 neelamchawla

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

neelamchawla avatar Jul 11 '20 13:07 neelamchawla