jQuery Validate 1.7在jQuery 1.5上打破$ .getJSON()?

时间:2011-02-03 15:42:52

标签: jquery jquery-validate

美好的一天!

我正在使用getJSON()在jQuery 1.4.4上运行插件,在升级到1.5之后,不会调用回调。返回的JSON有效(我已使用验证器检查过)。

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

似乎我想出了如何创建测试用例,似乎JQuery验证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);

2 个答案:

答案 0 :(得分:5)

答案 1 :(得分:0)

这可能已经有详细记录,但为了以防万一,this post上的答案为我做了。基本上,更新到jQuery Validate 1.8,它将适用于jQuery 1.5.2。谢谢@ alexander-kahoun!