Good day!
I've running plugin on jQuery 1.4.4 with getJSON()
, after uprade to 1.5 callback is not called. The returned JSON is valid (I've checked with validator).
Before digging more I'd like to as if this a common problem? Also I noticed additional get parameter ?callback=...
which jQuery adds to the URL
Thanks in advance!
Edit: 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 = $开发者_如何学C.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);
As you might know, jQuerys ajax module was almost completly rewritten. It now uses a promise maker object which fires when the new jXHR object reaches state resolved
.
If you are calling .getJSON()
yourself, you might try to invoke it like:
$.getJSON('/path/file').then(function() {
// success
}, function() {
// fail
});
If the plugin you use is calling .getJSON()
, well thats a problem unless you can/want fix a possible problem yourself. Anyway, even if this system is new it "should" be backwards compatible.
.ajax
have been changed substantially in jQuery 1.5. There is now a new object called jqXHR
that is returned instead of XHRHttpRequest
, but it should be backwards compatible. Unfortunately the docs for .getJSON
is outdated and still show the docs for 1.4.4. I recommend you to check the updated docs for .ajax
instead and see if you can figure it out.
?callback=
is added to the uri to support jsonp
and/or cross-domain requests, so if you are doing any of this it will be added automatically.
It seems to be a bug:
https://github.com/jzaefferer/jquery-validation/issues/#issue/36
Thanks for the response here: jQuery Validate 1.7 breaks $.getJSON() on jQuery 1.5?
You can also temporarily use this hack, documented here: http://bugs.jquery.com/ticket/8084
// HACK:
// jquery-1.5 sets up jsonp for all json ajax requests
// undo the jsonp setting here so the json requests work again
$.ajaxSetup({
jsonp: null,
jsonpCallback: null
});
精彩评论