Mootools的Ajax请求后追加HTML [英] Mootools appending html after an ajax request
本文介绍了Mootools的Ajax请求后追加HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Ajax调用,看起来像这样,
I have an ajax call that looks like this,
$('campaignType').addEvent('change', function(){
alert($('campaignType').value);
var request = new Request({
method: 'get',
url: '/admin/admin_' + $('campaignType').value + '.php',
onRequest:function() {
alert('Request has been made, please be patient')
},
onComplete:function(response) {
$('campaignForm').append(response);
}
}).send();
});
不过,我似乎从本质上会发生什么取决于什么`$的值('campaignType)一些HTML是从另一个文件返回,无法获得HTML追加到我的容器。任何一个关心给我一些建议吗?
Essentially what happens is depending on what the value of `$('campaignType') some HTML is returned from another file, however I cannot seem to get the HTML to append on to my container. Any one care to give me some advice?
感谢
推荐答案
贝尔巴托夫的解决方案是接近,但一个坏的解决方案,因为它再现了全元素含量和销毁附加的事件处理程序。一个更好的解决办法是:
Dimitar's solution is close but is a bad solution as it recreates the whole element contents and destroys attached event handlers. A better solution would be:
Element.implement({
append: function(newhtml) {
return this.adopt(new Element('div', {html: newhtml}).getChildren());
}
});
这其实是什么Request.HTML内部做。
this is actually what Request.HTML internally does.
这篇关于Mootools的Ajax请求后追加HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文