我只想在执行“removeDocx”函数时才更新页面。 但在我的情况下,定时器的超时被认为是“等待”功能的完成。 问题在哪里,我该如何解决? 有的代码的示例:
$(function() {
$.when(wait()).done(function() {
location.href = location.href;
});
});
function wait() {
var pm = { ISN_DOC: GetrcId(document.location.href) };
if (isNaN(pm.ISN_DOC))
setTimeout(wait, 500);
else removeDocx();
}
function removeDocx() {
var def = $.Deferred();
var url = "MinPrj/Collage.asmx/clearPattern?isn_doc=" + pm.ISN_DOC;
$.ajax({
type: 'POST',
url: rootpath + url,
contentType: 'application/json'
}).done(function (r) {
def.resolve();
}).fail(def.reject());
return def;
}
您正在调用'wait()'并将其返回值传递给'$ .when'。由于“等待”不会返回任何内容,因此您如何期望它可以正常工作? –
您没有'$ .ajax'的'data'参数。当你没有内容时,为什么你要设置'application/json'的内容类型? – Quentin