missing ] after element list parsing JSON
I was working on a little web application front end submitting a form and processing a result asynchronously using jQuery. I wrote a little JavaScript snippet that looks something like the following:
$.post(
"submitForm.jsp",
theForm.serialize(),
function(data){
var res = eval('(' + data + ')');
// do something with the result
}
);
Yeah, I know, eval() probably isn’t the best choice here but we need to support IE7 which doesn’t support JSON.parse natively. Anyway, after submitting I get the following error:
error: missing ] after element list parsing JSON
Turns out that jQuery will try to figure out if the result is JSON and parse it automatically. In this case data is already a JavaScript object and not a JSON string waiting to be parsed.
Leave a Reply
Sponsored Links
Fourth Woods Blog
Categories
- Culture and Copyright (1)
- Database (5)
- MySQL (1)
- Oracle (2)
- SQL Server (2)
- Emulation (1)
- Programming (41)
- Algorithms (4)
- C (11)
- Cpp (3)
- Design Patterns (1)
- Graphics (7)
- Java (4)
- JavaScript (9)
- JSP (1)
- Multimedia (5)
- Perl (1)
- Security (4)
- XML (1)
- Tips and Tricks (22)
- Uncategorized (2)
Tags
beginner
binary analysis
bufferoverflow
bug
bugs
c
cd
cdt
configuration
copyright
cpp
data
database
directx
disassember
eclipse
emulator
expert
explorer
facebook
factory
firefox
graphics
intermediate
iso
java
javascript
jquery
linux
maze
midi
mingw
multimedia
opengl
oracle
programming
screensaver
security
sql
sql server
tips
ubuntu
web development
windows
xml
