JQuery.post()回调函数在1.3.2中调用,但在1.4.2中没有

时间:2010-07-31 15:45:36

标签: jquery ajax post callback

使用JQuery 1.3.2调用JQuery.post()的回调函数,但不使用1.4.2调用。试图找到版本之间发生了哪些变化而没有成功。

<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

1 个答案:

答案 0 :(得分:1)

我认为作为一种解决方法,您可以转换为使用$ .ajax()(如果需要,在POST /同步模式下),那个“成功”回调似乎对我有用,而其他一些(例如“完成”) “)不要。

编辑:在jQuery 1.4+中可能还有一些更严格的JSON解析依从性 - 建议使用像http://jsonlint.com/这样的网站验证您的JSON输出...如果它没有验证您可能无法获得回调。检查单引号和双引号。

EDI2:请参阅有关jQuery 1.4+ JSON解析的信息:

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