【发布时间】:2016-07-21 01:27:38
【问题描述】:
我只想在执行“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。由于wait不返回任何内容,您希望它如何工作?? -
你没有
data参数到$.ajax。为什么在没有内容的情况下设置application/json的内容类型?
标签: javascript jquery ajax deferred .when