我在firefox的控制台检查了ajax响应。但是我需要在php中显示这个响应作为html表。谢谢提前

时间:2022-10-09 12:01:51

Here is my ajax code

这是我的ajax代码

$(document).ready(function(){
  $('.category-link').click(function(e){
  e.preventDefault();
  var href = $(this).data('hash');
  var value = href.substring(1);
  getresultCategory('ajax.php?Category='+value);
  });


   function getresultCategory(url){
    $.ajax({
   url:url,
    type:'GET',
    success:function(){ 
     alert('sucess');
  } 
 });
 }
});
</script>";

Here is the response I got in firefox console

这是我在firefox控制台得到的响应

<div id="data-result">
<table class='cat_table'>
<tr><td>WFM</td><td>Name</td><td>9</td><td>13</td><td>1</td><td>1</td>
<td>32</td></tr>
<tr><td>CCE</td><td>Name</td><td>2</td><td>2</td><td>5</td><td>2</td>
<td>3</td></tr>
<tr><td>PM</td><td>Name</td><td>4</td><td>8</td><td>7</td><td>3</td>
<td>25</td></tr></table></div>

I want this response in my display as html table in php

我希望这个响应以php的html表显示

2 个解决方案

#1


2  

Put an element in your HTML to receive the response, for example:

在HTML中放置一个元素来接收响应,例如:

<div id="myTable"></div>

Then modify the success function of your AJAX call to place the data from the call into the HTML element:

然后修改AJAX调用的成功函数,将调用中的数据放入HTML元素:

success:function(data){ // add a variable in the function 
     $('#myTable').html(data); // place the data in the HTML element
} 

#2


0  

create one div tag to receive output of ajax response

创建一个div标签以接收ajax响应的输出。

<div id="datatabe"></div>

then modify your ajax response on ajax success

然后修改ajax响应

success:function(data){ // add a variable in the function 
 $('#datatabe').append(data); // place the data in the HTML element

}

}

#1


2  

Put an element in your HTML to receive the response, for example:

在HTML中放置一个元素来接收响应,例如:

<div id="myTable"></div>

Then modify the success function of your AJAX call to place the data from the call into the HTML element:

然后修改AJAX调用的成功函数,将调用中的数据放入HTML元素:

success:function(data){ // add a variable in the function 
     $('#myTable').html(data); // place the data in the HTML element
} 

#2


0  

create one div tag to receive output of ajax response

创建一个div标签以接收ajax响应的输出。

<div id="datatabe"></div>

then modify your ajax response on ajax success

然后修改ajax响应

success:function(data){ // add a variable in the function 
 $('#datatabe').append(data); // place the data in the HTML element

}

}