jquery在ajax调用后绑定函数和触发器
function bindALLFunctions() {
..all triggers functions related go here
};
$.ajax({
type: 'POST',
url: myURL,
data: { thisParamIdNo: thisIdNo },
success: function(data){
$(".incContainer").html(data);
bindALLFunctions();
},
dataType: 'html'
});
我是 ajax 和 JQuery 新手。 我的 js-jquery 代码中有上述 ajax 调用。 bindALLFunctions(); 用于在ajax调用后重新调用所有触发器和函数。它工作得很好,正如预期的那样。但是,我在某处读到最好在初始操作完成后加载某些内容,因此我尝试添加/编辑以下两个内容,但没有成功。 有什么想法吗?
1) -> $(".incContainer").html(data, function(){
bindALLFunctions();
});
2) -> $(".incContainer").html(data).bindALLFunctions();
function bindALLFunctions() {
..all triggers functions related go here
};
$.ajax({
type: 'POST',
url: myURL,
data: { thisParamIdNo: thisIdNo },
success: function(data){
$(".incContainer").html(data);
bindALLFunctions();
},
dataType: 'html'
});
I am new to ajax and JQuery.
I have the above ajax call in my js-jquery code. bindALLFunctions(); is used to re-call all the triggers and functions after the ajax call. It works all fine and good as expected. However, I have read somewhere that is better to load something after the initial action is finished, so I have tried to add/edit the following two without any success.
Any ideas?
1) -> $(".incContainer").html(data, function(){
bindALLFunctions();
});
2) -> $(".incContainer").html(data).bindALLFunctions();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许您应该看看 live 和 委托 函数。您可以在应用程序开始时设置一个唯一的事件处理程序,所有加载的 ajax 代码都将自动绑定:
但如果您更喜欢使用 Jquery.ajax 调用,则必须执行以下操作:
并转换
bindALLFunctions as:
只会将事件绑定在给定选择器“下”。
Perhaps you should have a look to the live and delegate functions. You can set a unique event handler at the beggining of your app and all your loaded ajax code will be automatically binded:
But if you prefer to use Jquery.ajax call you have to do something like this:
and transform
bindALLFunctions
as:that will only bind events "under" the given selector.
你最初的代码很好。新版本不起作用,因为 html() 函数没有回调函数。
Your initial code was fine. The new version does not work because html() function does not have a callback function.
很难从你的问题中看出你想问什么,但我猜你想知道 ready 函数。它可以让您在文档可用后调用bindALLFunctions;只需执行
$(document).ready(bindALLFunctions)
或$(document).ready(function() { bindALLFunctions(); })
即可。It's hard to tell from your question just what you intend to ask, but my guess is that you want to know about the ready function. It would let you call your bindALLFunctions after the document was available; just do
$(document).ready(bindALLFunctions)
or$(document).ready(function() { bindALLFunctions(); })
.