jQuery:在1.3.2中运行成功但在1.4.2中运行不成功

没有什么是错的,只要我将lib改为1.3.2,我的成功东西就可以了吗? 怎么会? 甚至没有TEST的警报出现..

这是发生在这里的代码:

function crop() { $.ajax({ type: "POST", dataType: 'json', url:"functions.php?action=crop", data: { x: $('#x').val(),y: $('#y').val(),w: $('#w').val(), h: $('#h').val(),fname:$('#fname').val(),fixed:fixed, sizew:sizew,sizeh:sizeh}, success: function(response) { alert('TEST'); if(!fixed) // Missing { } { $("#showPhoto").css({overflow:"auto"}); // Missing ; } $("#showPhoto").html( $(document.createElement("img")).attr( "src",response.filename)).show(); $("#showPhoto").after("There you go...").show(); $("#image").slideUp(); }, error:function(response) { console.log('error: ', response); } }); } 

如何使它与jquery 1.4.2库一起使用?

回来的JSON无效,你发布的例子如下:

 ({"filename":"images\/profilePhoto\/thumbs\/1283596240.jpg"}) 

我在页面中得到的回复:

 ({"filename":"1283597560.jpg"}) 

两者都不是有效的JSON,你需要删除那里的()包装器。 您可以在此处查看您的JSON响应的有效性: http : //www.jsonlint.com/

1.3.2与1.4.2的区别在于1.4.0中jQuery添加了严格的JSON检查,如果它无效则会失败(因此它可以更好地利用浏览器的本机JSON解析器)。

从1.4发行说明 :

严格的JSON解析,使用本机JSON.parse :( jQuery.ajax()Documentation , Commit 1 , Commit 2 , Commit 3 )

jQuery 1.3及更早版本使用JavaScript的eval来评估传入的JSON。 jQuery 1.4使用本机JSON解析器(如果可用)。 它还validation传入的JSON的有效性,因此jQuery在jQuery.getJSON中以及将“json”指定为Ajax请求的dataType时,将拒绝格式错误的JSON(例如{foo: "bar"} )。