0

Please can you help -- why does this JSON not work

the head of my page looks like this

<script src="Scripts/json2.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/JScript.js" type="text/javascript"></script>

and my ajax looks like this

var p = { "myText": JSON.stringify(tableOBJ) };

$.ajax({
    type: "POST",
    url: "Default2AJAX.aspx",
    data: p,
    success: function (data) {

        var obj = JSON.parse(data);

    }
});

In firefox I get this error on the JSON

Error: syntax error
Source File: /Scripts/json2.js
Line: 4
Source Code:
<!DOCTYPE html>

In IE 7 I get JSON undefined

in ie 8 i get

SCRIPT1002: Syntax error json2.js, line 4 character 1

In ie 9 i get

SCRIPT1002: Syntax error json2.js, line 4 character 1

How do I fix this? as I have added json2.js but it appear if the browser doesnt need it it throws an error?

1
  • its my javascript file with my ajax in it Commented Aug 7, 2012 at 19:35

4 Answers 4

3

Change Scripts/json2.js to point to a real copy of json2.js. At the moment it is pointing to an HTML document (probably a 404 error page).

Sign up to request clarification or add additional context in comments.

Comments

2

I am betting that the file "Scripts/JScript.js" does not exist on your server and that the Source Code: <!DOCTYPE html> is a 404 error page.

Comments

2

@Hello-Word & @Rocket Hazmat:

The file at github link is an html file. To solve the problem:

  1. Download json2.js
  2. Change the file extension to html
  3. Open the file in a web browser
  4. Scroll down the page, copy the javascript code portion, and save it to a new file as json2.js

BTW, thanks to Douglas for the json parser. Makes my life much easier.

Comments

1

There appears to be an error in the json2.js file you are using -- at least IE 8 & 9 agree that an error exists on line 4 of that file.

1 Comment

thanks you where correct it was my json2 file that had an error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.