开发者

JQuery.post() callback function called in 1.3.2 but not in 1.4.2

The callback function of the JQuery.post() is called with 开发者_如何学GoJQuery 1.3.2 but not with 1.4.2. Tried to find what changed between the versions without successs.

<html>
<head>
<script type="text/javascript" 
   src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"
></script>
<script type="text/javascript">
function f() {
   var j;
   $.post('/python/publisher/jqueryjson.py', {x: 1}, function(j){g(j);}, 'json');
}
function g(j) {
   console.log(j.result);
}
</script>
</head>

<body>
<input type="button" onclick="f();">
</body>
</html>

Response Headers

HTTP/1.1 200 OK
Date: Sat, 31 Jul 2010 18:55:26 GMT
Server: Apache/2.2.3 (CentOS)
Content-Length: 14
Connection: close
Content-Type: application/json

Request Headers

POST /python/publisher/jqueryjson.py HTTP/1.1
Host: teste.dkt
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.7) Gecko/20100723 Fedora/3.6.7-1.fc13 Firefox/3.6.7
Accept: application/json, text/javascript, */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://teste.dkt/python/publisher/jqueryjson.html
Content-Length: 3
Pragma: no-cache
Cache-Control: no-cache


I believe as a workaround you can change over to using $.ajax() (in POST/sync mode if necessary), the "success" callback on that one seems to work for me while some others (such as "complete") do not.

EDIT: There may also be some stricter JSON parsing adherence in jQuery 1.4+ -- recommend verifying your JSON output with a site like http://jsonlint.com/ ... if it does not validate you may not get your callback. Check single vs. double quotes.

EDI2: See information here on jQuery 1.4+ JSON parsing:

http://yehudakatz.com/2010/01/15/jquery-1-4-and-malformed-json/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜