ajax 请求文档,在ajax请求之后准备好jQuery文档

我在更新ajax请求后未准备好的元素时遇到问题。

如果我在页面加载时运行我的myFunction()函数,就像这样:

$(function() {

myFunction();

}

我没有任何问题。但是,如果我然后使用像这样的东西

$.ajax({

url: this.href,

dataType: "script",

complete: function(xhr, status) {

myFunction();

}

});

返回$(".myElement").replaceWith("htmlHere")。当完整事件触发时,元素根本就没有准备好。如果我在那里设置延迟,它再次正常工作。

当DOM准备就绪时,还有除“完成”之外的任何其他事件被触发吗?

更新

这是实际的代码:

$(function() {

$("a.remote").live("click", function(e) {

$.ajax({

url: this.href,

dataType: "script",

success: function(xhr, status) {

myFunction();

}

});

e.preventDefault();

return false;

});

myFunction();

});

function myFunction() {

// Modify the dom in here

}

失踪者);对我来说只是一个错字。

我现在尝试使用成功而不是完成,但似乎没有任何区别。