开发者

upgraded to jquery 1.4.1 & now getting parse error

I have tried upgrading from jQuery 1.2.6 to 1.4.1. A JSON query is now failing with error : "parseerror, invalid label"

I 开发者_如何学编程have simplified the code to bare minimum.

var jsonUrl = "process_01.php";
$.ajax({
 type: "POST",
 url:  jsonUrl,   
 data: "var=myVar",        
 dataType: "json",    
 beforeSend: function(msg) {
 },
 success: function(msg) {
 },
 error: function (msg, textStatus, errorThrown) {
   alert("an error has occured (" + textStatus + " " + errorThrown +")" );
   }
});
return false;
}

Output of php program is {"foo":"bar","IsTrue":"true"}

I can see this in firebug


Make sure your content type is set to application/json.

Also look at this, looks similar to your problem.


There should be single quotes around the values sent. Like this guy did.


If it helps anyone else who stumbles across this, the original poster said he wasn't sending out the header as application/json. In my case I ran into trouble parsing quoted apostrophes inside a double quoted string like this:

{"description": "An invalid person\'s JSON"}

Looks like 1.3.2 took this, but 1.4.1 rejects it. Guess I'll have to find a more graceful approach to escaping on the server side. See http://jsbin.com/oveci3 for what I used for reference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜