本文介绍了使用ajax注入html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含一些div元素的HAML页面.单击按钮时,需要将其注入到另一页的div中.我该怎么做呢?谢谢
I have a HAML page with some div elements. I need to inject this into a div on another page when a button is clicked. how do i do this? thanks
推荐答案
您必须从jQuery.com添加jQuery插件.您可以下载插件或使用链接 http://ajax.aspnetcdn.com/ajax/jQuery/jquery -1.5.1.min.js 作为js文件中的src.
You have to add the jQuery plugin from jQuery.com. you can download the plugin or use the linkhttp://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js as src in the js file.
然后使用以下代码
$(document).ready(function(){
$("#your_button_Id").click(function(){
$.ajax({
url: "test.html",
context: document.body,
success: function(response){
$('#div_Id').html(response);
}
});
});
});
希望这会有所帮助!!!编码愉快.
Hope this helps!!!happy coding.
这篇关于使用ajax注入html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!