Bizarre Javascript JSON undefined error
Posted
by
Nate C-K
on Stack Overflow
See other posts from Stack Overflow
or by Nate C-K
Published on 2009-11-26T06:15:05Z
Indexed on
2011/01/16
13:53 UTC
Read the original article
Hit count: 313
I'm experiencing an error that I haven't been able to find any mention of anywhere. I'm developing an AJAX-enabled WCF web service with ASP.NET. In my ASP.NET master page's , I included the json.js file, copied fresh from json.org. When I run the page, it fails (VS 2008 catches a Javascript exception) on the first line of code in json.js (following lots of comments), which is:
JSON = JSON || {};
The error says that JSON is undefined:
Microsoft JScript runtime error: 'JSON' is undefined
Well, duh! That's why the line is testing if it's defined and if so setting it to an empty object! It is supposed to be undefined, right? Last I heard it was not an error in Javascript to perform such an operation on an undefined variable.
Can anyone give me a clue as to what's going on here? I suspect it's something gone wrong elsewhere that's somehow causing this problem. I don't have deep experience with either Javascript or ASP.NET so it might be that I'm missing some common gotcha in the setup.
© Stack Overflow or respective owner