jQuery Validate 1.7在jQuery 1.5上破坏了$ .getJSON()? [英] jQuery Validate 1.7 breaks $.getJSON() on jQuery 1.5?

查看:76
本文介绍了jQuery Validate 1.7在jQuery 1.5上破坏了$ .getJSON()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天!

我正在使用getJSON()在jQuery 1.4.4上运行一个插件,在升级到1.5之后,未调用该回调.返回的JSON有效(我已经通过验证程序进行了检查).

我还注意到jQuery添加到URL的其他get参数?callback=...

似乎我想出了如何创建测试用例,似乎是JQuery validate 1.7(最新版本)引起的:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="ru">

<head>
    <title>

    </title>

    <meta http-equiv="content-type" content="text/html; charset=utf8" />     
    <script type="text/javascript" src="js/jquery-1.5.min.js"></script>
<!--    
    If I uncomment this - it will not work
    <script type="text/javascript" src="js/jquery.validate.js"></script>
-->
</head>
<body>
<script type="text/javascript">
$(function(){
    $.ajaxSetup({ cache: false });
    $('#clickme').click(function(){
        var params = {userid : 'some-user-id-to-choose-right-temp-FTP-folder-for-the-user'};
        $.getJSON('/ajax-page_material-edit-ftp-filelist.php', params, function(data) {
            console.log(data);
        });
    });
});
</script>

<a href="#" id="clickme">Click Me!</a>

</body>
</html>

也许插件中的这段代码是导致这种情况的原因:

// ajax mode: abort
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort() 
;(function($) {
    var ajax = $.ajax;
    var pendingRequests = {};
    $.ajax = function(settings) {
        // create settings for compatibility with ajaxSetup
        settings = $.extend(settings, $.extend({}, $.ajaxSettings, settings));
        var port = settings.port;
        if (settings.mode == "abort") {
            if ( pendingRequests[port] ) {
                pendingRequests[port].abort();
            }
            return (pendingRequests[port] = ajax.apply(this, arguments));
        }
        return ajax.apply(this, arguments);
    };
})(jQuery);

解决方案

已创建了问题单并已提交了补丁程序

https://github.com/jzaefferer/jquery-validation/issues/#issue/36

https://github.com/bigfix/jquery-validation/commit/9aa53f9241224ba349f9fe1b2c801be0f431b63b >

Good day!

I'm running a plugin on jQuery 1.4.4 with getJSON(), after uprade to 1.5, the callback is not called. The returned JSON is valid (I've checked with validator).

Also I noticed additional get parameter ?callback=... which jQuery adds to the URL

It seems I figured out how to create a test case and it seems that JQuery validate 1.7 (latest version) is the cause:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="ru">

<head>
    <title>

    </title>

    <meta http-equiv="content-type" content="text/html; charset=utf8" />     
    <script type="text/javascript" src="js/jquery-1.5.min.js"></script>
<!--    
    If I uncomment this - it will not work
    <script type="text/javascript" src="js/jquery.validate.js"></script>
-->
</head>
<body>
<script type="text/javascript">
$(function(){
    $.ajaxSetup({ cache: false });
    $('#clickme').click(function(){
        var params = {userid : 'some-user-id-to-choose-right-temp-FTP-folder-for-the-user'};
        $.getJSON('/ajax-page_material-edit-ftp-filelist.php', params, function(data) {
            console.log(data);
        });
    });
});
</script>

<a href="#" id="clickme">Click Me!</a>

</body>
</html>

Maybe this code in plugin is the cause:

// ajax mode: abort
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort() 
;(function($) {
    var ajax = $.ajax;
    var pendingRequests = {};
    $.ajax = function(settings) {
        // create settings for compatibility with ajaxSetup
        settings = $.extend(settings, $.extend({}, $.ajaxSettings, settings));
        var port = settings.port;
        if (settings.mode == "abort") {
            if ( pendingRequests[port] ) {
                pendingRequests[port].abort();
            }
            return (pendingRequests[port] = ajax.apply(this, arguments));
        }
        return ajax.apply(this, arguments);
    };
})(jQuery);

解决方案

A ticket for the issue was already created and a patch has been submitted

https://github.com/jzaefferer/jquery-validation/issues/#issue/36

https://github.com/bigfix/jquery-validation/commit/9aa53f9241224ba349f9fe1b2c801be0f431b63b

这篇关于jQuery Validate 1.7在jQuery 1.5上破坏了$ .getJSON()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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