방금 jquery 1.11.1로 이동했습니다 (이 프로젝트를 시작하기 전 1.2.x). 엘리먼트에 응답 text/html을 가져 오는 데 사용 된 $ .load 함수는 갑자기 콜백을 발생시키는 것처럼 보이지 않습니다! 실제로로드 할 때 Jquery로드 콜백이 실행되지 않습니다.
$("#thing").load("page", null, callback);
그래서 내가 그것을 $ 들이게 사용하여 자체에서 그것을 PULS 다음 콜백 실제로의 "완전한"기능에 해고되고, $ 아약스를 사용하는 페이지를 잡고 예상대로 .. JQuery와 코드를 디버깅 $ .ajax. 이 기능은 아약스의 성공 여부에 관계없이 항상 발사됩니다. 잠시 동안 자신을 미친 운전 후, 난 그냥 내 자신이 정말 화가 진행되지 않은 테스트 할 호출을 호출하려고 ...이 내가
$.ajax({url:"page"})
.done(function(r){
$("#thing").html(r);
})
.complete(function(){alert("complete");});
이이 요소를 채 웁니다하지만 나에게 제공하지 않습니다 않는 찾을 것입니다 alernt .. 그러나 아래는 나에게 경고를 준다! .. 왜?
$.ajax({url:"page"})
.done(function(r){
//$("#thing").html(r);
alert("done...?");
})
.complete(function(){alert("complete");});
내가 대신 "전체"의 "항상"사용에 대한 코멘트를 들어
UPDATE 1
.. 둘 다 완전한 경고를 얻을. 나는 "부하"없습니다 "아약스를"사용하려는,이 JQ의 코드가 "완료"를 사용하는 방법 1.11.1
// Keep a copy of the old load method
var _load = jQuery.fn.load;
/**
* Load a url into a page
*/
jQuery.fn.load = function(url, params, callback) {
if (typeof url !== "string" && _load) {
return _load.apply(this, arguments);
}
var selector, response, type,
self = this,
off = url.indexOf(" ");
if (off >= 0) {
selector = jQuery.trim(url.slice(off, url.length));
url = url.slice(0, off);
}
// If it's a function
if (jQuery.isFunction(params)) {
// We assume that it's the callback
callback = params;
params = undefined;
// Otherwise, build a param string
} else if (params && typeof params === "object") {
type = "POST";
}
// If we have elements to modify, make the request
if (self.length > 0) {
jQuery.ajax({
url: url,
// if "type" variable is undefined, then "GET" method will be used
type: type,
dataType: "html",
data: params
}).done(function(responseText) {
// Save response for use in complete callback
response = arguments;
self.html(selector ?
// If a selector was specified, locate the right elements in a dummy div
// Exclude scripts to avoid IE 'Permission Denied' errors
jQuery("<div>").append(jQuery.parseHTML(responseText)).find(selector) :
// Otherwise use the full result
responseText);
}).complete(callback && function(jqXHR, status) {
self.each(callback, response || [ jqXHR.responseText, status, jqXHR ]);
});
}
return this;
};
예고 ..
'.complete'은 1.11에 존재하지 않으며'.always'입니다. 첫 번째 예는 효과가 있습니다. 'null '을 제거하십시오. –
이것은 제가하는 일이 아닙니다 .. 이것은 실제 jquery "load"메소드가하는 일입니다. 나는 이걸 제어 할 수 없습니다. –
... 귀하의 의견을 이해하지 못합니다. 봐. –