【问题标题】:JQuery.post() callback function called in 1.3.2 but not in 1.4.2JQuery.post() 回调函数在 1.3.2 中调用但在 1.4.2 中没有
【发布时间】:2010-07-31 15:45:36
【问题描述】:

JQuery.post() 的回调函数在 JQuery 1.3.2 中调用,但在 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

【问题讨论】:

    标签: jquery ajax post callback


    【解决方案1】:

    我相信作为一种解决方法,您可以改用 $.ajax()(必要时在 POST/sync 模式下),该回调的“成功”回调似乎对我有用,而其他一些回调(例如“完成") 没有。

    编辑:在 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/

    【讨论】:

    • 是的,问题是 JSON 格式错误。
    猜你喜欢
    • 1970-01-01
    • 2011-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 2012-04-23
    • 1970-01-01
    相关资源
    最近更新 更多