gpt4 book ai didi

javascript - 如何通过ajax追加表体

转载 作者:行者123 更新时间:2023-12-01 03:33:07 24 4
gpt4 key购买 nike

我想将表的 tbody 附加到已经存在的表中,如何附加表。实际上,我想从整个表中搜索单词。通过 javascript 和 ajax。如何在 search.php 页面中附加表 tbody ,请帮我解决这个问题。 搜索.php

   <div >
<table id="table">
<thead>
<th>
Email
</th>
<th>
Firstname
</th>
<th>
Lastname
</th>
<th>
Companyname
</th>
<th>
Title
</th>
<th>
LinkedinURL
</th>
<th>
Domain
</th>
<th>
Companylocation
</th>
<th>
Companysizecategory
</th>
<th>
Companyfunding
</th>
<th>
Companyindustry
</th>
<th>
Companywebtech
</th>
<th>
DateDownloaded
</th>
<th>
ElucifyAccountID
</th>
</thead>


</table>
</div>
</form>
</div>
</form>
</body>
</html>
<script>
$("#search").keyup(function()
{
var search=$(this).val();
$.ajax({
type:"POST",
url:"searchajax.php",
data:{
ajaxsearch:search,
},
success:function(data){

alert("success");
},
error:function(){
alert('error');
}

});
});
</script>

ajax.php

if (!empty($_POST['ajaxsearch'])) 
{
$search=$_POST['ajaxsearch'];
$sql="SELECT * from company";
$sql_query=mysql_query($sql);
$logicStr="WHERE ";
$count=mysql_num_fields($sql_query);
for($i=0 ; $i < mysql_num_fields($sql_query) ; $i++){
if($i == ($count-1) )
$logicStr=$logicStr."".mysql_field_name($sql_query,$i)." LIKE '%".$search."%' ";
else
$logicStr=$logicStr."".mysql_field_name($sql_query,$i)." LIKE '%".$search."%' OR ";
}

$sql="SELECT * from company ".$logicStr;
//echo "SELECT * from company ".$logicStr;
$get=mysql_query($sql);

$i=0;
while($getresult=mysql_fetch_array($get))
{

echo '<tbody>';
echo'<tr>';
echo '<td>';
echo $getresult['Email'];
echo '</td>';
echo'<td>';
echo $getresult['Firstname'];
echo '</td>';
echo '<td>';
echo $getresult['Lastname'];
echo '</td>';
echo'<td>';
echo $getresult['Companyname'];
echo '</td>';
echo'<td>';
echo $getresult['Title'];
echo'</td>';
echo'<td>';
echo $getresult['LinkedinURL'];
echo'</td>';
echo '<td>';
echo $getresult['Domain'];
echo'</td>';
echo'<td>';
echo $getresult['CompanyLocation'];
echo '</td>';
echo '<td>';
echo $getresult['Companysizecategory'];
echo '</td>';
echo '<td>';
echo $getresult['Companyfunding']
echo'</td>';
echo'<td>';
echo $getresult['Companyindustry'];
echo '</td>';
echo '<td>';
echo $getresult['companywebtech'];
echo'</td>';
echo '<td>';
echo $getresult['Datedownloaded'];
echo'</td>';
echo '<td>';
echo $getresult['ElucifyAccountID'];
echo'</td>';
echo'</tr>';
echo'</tbody>';


$i++;
}
}
else
{
echo'<script>window.alert("enter valid Data")</script>';
}
?>

最佳答案

尝试下面的代码:

$.ajax({
type:"POST",
url:"searchajax.php",
data:{
ajaxsearch:search,
},
success:function(data){
$('#table thead').insertAfter(data);
},
error:function(){
alert('error');
}
});

关于javascript - 如何通过ajax追加表体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44432512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com