Jump to content

parsing JSON in firefox fails


Recommended Posts

Hey guys, I'm new to this forum!

Use to be an oldschool flash developer (erik.newgrounds.com) and am now seriously looking at building games in HTML5.

I had zero problems until i opened my game in Firefox (54.0.1 (32-bits), and  Pixi v4.5.0..) and it threw the following error:
TypeError: resources['assets/images/bodyparts.json'].textures is undefined[Meer info]

After digging a bit deeper and logging the above mentioned resource object i see:

Object { _flags: 2, name: "assets/images/bodyparts.json", url: "assets/images/bodyparts.json", extension: "json", data: null, crossOrigin: "", loadType: 1, xhrType: "json", metadata: Object, error: Error, nog 17… }

When i click the Error message i see the following error:
Error trying to parse loaded json: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

I cant find anything wrong with my json, even JSONLint tells me its ok. Also in Chrome everything works perfectly fine.
JSON object is attached to this topic.

Any idea whats going on here?

Thanks for the help!


Firefox v


Link to comment
Share on other sites

Welcome, fellow Flash-developer!

For any html5 engine/rendering_lib if you see a problem with json, regardless of your browser, please look in devtools in "network" tab and analyze the XHR request.

In most of cases, its CORS problem, and you can search through this subforum and https://github.com/pixijs/pixi.js/issues , we had a large number of those issues.

Link to comment
Share on other sites

I couldn't find anything that answers my particular issue with the character being wrong. I did find several cors issues.
After some more spitting ,  when i trace my json text in firefox within pixi.js i see the following characters:


Im now looking i can fix my JSON ..

Link to comment
Share on other sites

Hi Ivan, you were right all along.. obviously i never doubted you ;)

Im using XAMPP as my local server, and it were indeed CORS issues.

Create a file called ".htaccess" in the directory of my files and add the following to the file.

Header set Access-Control-Allow-Origin "http://localhost:8080/"

Works like a charm now!

Thanks again!



Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...