Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3784622
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:24:17+00:00 2026-05-19T11:24:17+00:00

Hey there, I have an Arabic contact script that uses Ajax to retrieve a

  • 0

Hey there, I have an Arabic contact script that uses Ajax to retrieve a response from the server after filling the form.

On some apache servers, jQuery.parseJSON() throws an invalid json excepion for the same json it parses perfectly on other servers. This exception is thrown only on chrome and IE.

The json content gets encoded using php’s json_encode() function. I tried sending the correct header with the json data and setting the unicode to utf-8, but that didn’t help.

This is one of the json responses I try to parse (removed the second part of if because it’s long):

{"pageTitle":"\u062e\u0637\u0623 \u0639\u0646\u062f \u0627\u0644\u0625\u0631\u0633\u0627\u0644 !"}

Note: This language of this data is Arabic, that’s why it looks like this after being parsed with php’s json_encode().

You can try to make a request in the examples given down and look at the full response data using firebug or webkit developer tools. The response passes jsonlint!

Finally, I have two urls using the same version of the script, try to browse them using chrome or IE to see the error in the broken example.

The working example : http://namodg.com/n/

The broken example: http://www.mt-is.co.cc/my/call-me/

Updated: To clarify more, I would like to note that I manged to fix this by using the old eval() to parse the content, I released another version with this fix, it was like this:

// Parse the JSON data
try
{
    // Use jquery's default parser
    data = $.parseJSON(data);
}
catch(e)
{
    /*
     * Fix a bug where strange unicode chars in the json data makes the jQuery
     * parseJSON() throw an error (only on some servers), by using the old eval() - slower though!
     */
    data = eval( "(" + data + ")" );
}

I still want to know if this is a bug in jquery’s parseJSON() method, so that I can report it to them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T11:24:18+00:00Added an answer on May 19, 2026 at 11:24 am

    Found the problem! It was very hard to notice, but I saw something funny about that opening brace… there seemed to be a couple of little dots near it. I used this JavaScript bookmarklet to find out what it was:

    javascript:window.location='http://www.google.com/search?q=u+'+('000'+prompt('String?').charCodeAt(prompt('Index?')).toString(16)).slice(-4)
    

    I got the results page. Guess what the problem is! There is an invisible character, repeated twice actually, at the beginning of your output. The zero width non-breaking space is also called the Unicode byte order mark (BOM). It is the reason why jQuery is rejecting your otherwise valid JSON and why pasting the JSON into JSONLint mysteriously works (depending on how you do it).

    One way to get this unwanted character into your output is to save your PHP files using Windows Notepad in UTF-8 mode! If this is what you are doing, get another text editor such as Notepad++. Resave all your PHP files without the BOM to fix your problem.

    Step 1: Set up Notepad++ to encode files in UTF-8 without BOM by default.
    UTF-8 without BOM setting in New Document tab of Preferences

    Step 2: Open each existing PHP file, change the Encoding setting, and resave it.
    Encoding...Encode in UTF-8 without BOM

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey there i have this code that should save a file from sql server
Hey there, I have a program that uses a sql express local DB. I
hey there, i have a div that expands when the page is loaded, now
Hey there. I have a c# application that parses txt files and imports the
hey there guys and girls i have this code that saves json as a
hey there i am having problem i have List<List<memoryCard>> that i want to show
Hey there. I have an image that I am absolutely positioning. In Firefox it
Hey there. Basically, I have a batch-file, that goes through all model and texture
Hey there, I have dynamic question marks on my landing page that scroll with
hey there guys and girls i have this code that should download a json

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.