jquery ajax请求echo html数据 [英] Jquery ajax request echo html data
本文介绍了jquery ajax请求echo html数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在向我的PHP脚本发出一个ajax请求,这个请求会回显出一定数量的表(每次不同),当用户单击submit_form按钮时,我想将其包括在原始页面上。我的问题是如何让jquery将此表显示到 table_layout
div?
HTML:
< div id =table_layout> < / DIV>
JQUERY
$ .ajax({
类型:'GET',
url:'draw_tables.php',
dataType:'html',
data:dataString,
错误:函数(XMLHttpRequest,textStatus,errorThrown){
alert('error' );},
success:function(data){//appendto.('#table_layout')}
});
return false;
})
PHP(draw_tables.php)
echo'< table>';
echo'< input type =textname =ID>';
echo'< input type =textname =CLASS>';
echo'< / table>';
解决方案
例如,您可以创建一个ajax请求并填充与它共享
$ .get(draw_tables.php,function(data){
$(# table_layout)。html(data);
});
这会将您的 table_layout
id填入来自ajax请求的数据。
I'm making an ajax request to my PHP script which will echo out a certain # of tables ( different each time), that I want to include on my original page when a user clicks the submit_form button. My question is how can i get Jquery to display this table into the table_layout
div?
HTML :
<div id="table_layout"> </div>
JQUERY
$( ".submit_form" ).click(function( e ) {
$.ajax({
type : 'GET',
url: 'draw_tables.php',
dataType : 'html',
data: dataString ,
error : function(XMLHttpRequest, textStatus, errorThrown) {
alert('error'); },
success : function(data) { //appendto.('#table_layout') }
});
return false;
})
PHP (draw_tables.php)
echo '<table>';
echo '<input type="text" name="ID">';
echo '<input type="text" name="CLASS">';
echo '</table>';
解决方案
For example you could make an ajax request and fill the div with it
$.get("draw_tables.php", function(data) {
$("#table_layout").html(data);
});
This will fill your table_layout
id with the data from the ajax request.
这篇关于jquery ajax请求echo html数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文