jQuery:在1.3.2中运行成功,但在1.4.2中未成功 [英] jQuery: running success in 1.3.2 but not in 1.4.2

查看:106
本文介绍了jQuery:在1.3.2中运行成功,但在1.4.2中未成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Nothing is wrong, as soon as i change the lib to 1.3.2 my on success stuff works just fine? How comes? Not even the alert with TEST appears..

这是发生这种情况的代码:

Here's the code this is happening on:

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库一起使用?

How can i make it to work with jquery 1.4.2 library?

推荐答案

返回的JSON无效,例如您发布的示例:

The JSON coming back isn't valid, the example you posted:

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

我在页面中得到的回复:

And the response I got in the page:

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

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

Both aren't valid JSON, you need to remove the () wrapper on there. You can check your JSON response for validity here: http://www.jsonlint.com/

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

The 1.3.2 vs 1.4.2 difference is that in 1.4.0 jQuery added strict JSON checking, if it's not valid it'll fail (so it can take better advantage of browsers' native JSON parsers).

摘自1.4发行说明:

使用本机JSON.parse 进行严格的JSON解析:( jQuery. ajax()文档提交1 提交3 )

Strict JSON parsing, using native JSON.parse: (jQuery.ajax() Documentation, Commit 1, Commit 2, Commit 3)

jQuery 1.3及更早版本使用JavaScript的eval评估传入的JSON. jQuery 1.4使用本机JSON解析器(如果有).它还会验证传入的JSON的有效性,因此jQuery在 jQuery.getJSON 以及在将"json"指定为Ajax请求的dataType时.

jQuery 1.3 and earlier used JavaScript’s eval to evaluate incoming JSON. jQuery 1.4 uses the native JSON parser if available. It also validates incoming JSON for validity, so malformed JSON (for instance {foo: "bar"}) will be rejected by jQuery in jQuery.getJSON and when specifying "json" as the dataType of an Ajax request.

这篇关于jQuery:在1.3.2中运行成功,但在1.4.2中未成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆