Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将多个ajax成功划分为两个div_Php_Ajax_Html Table - Fatal编程技术网

Php 如何将多个ajax成功划分为两个div

Php 如何将多个ajax成功划分为两个div,php,ajax,html-table,Php,Ajax,Html Table,我有一个ajax脚本,如下所示: $.ajax({ type:"post", url:"process1.php", data:params, cache :false, async :false, success : function(res,data) { $("#qtycheck").html(res); $("#rangecheck").

我有一个ajax脚本,如下所示:

$.ajax({
        type:"post",
        url:"process1.php",
        data:params,
        cache :false,
        async :false,
        success : function(res,data) {
              $("#qtycheck").html(res);
              $("#rangecheck").html(data);
              return this;
              }
        });

<div id="qtycheck"></div>
<div id="rangecheck"></div>
正确结果:

<div id="qtycheck">
  <table> ...50...</table>
</div>
<div id="rangecheck">
   <table> ...1 - 100..</table>
</div>
实际:

<div id="qtycheck">
<table> ...50...</table>
<table> ...1 - 100..</table>
</div>
<div id="rangecheck"> success </div>
更新

要明确表的来源,请执行以下查询:

$sql= "SELECT .......";
$res=mysql_query($sql) or die(_ERROR26.": ".mysql_error());
$fields_num = mysql_num_fields($res);

echo "<table id ='appear2' border='1' style='border-collapse:collapse;font: 16px/20px Calibri, 
                Arial, Helvetica, sans-serif; background-color:white; ' width='auto'>";
        echo "<tr id='tblhead' style='text-align:center;'>";
        for($i=0; $i<$fields_num; $i++)
        {
                $field = mysql_fetch_field($res);
                echo "<td>{$field->name}</td>";
        }
        echo "</tr>\n";
        while($row = mysql_fetch_row($res))
        {
                echo "<tr>";
                foreach($row as $cell)
                echo "<td>$cell</td>";
                echo "</tr>\n";
        }

$sql= "SELECT .......";
$data=mysql_query($sql) or die(_ERROR26.": ".mysql_error());
$fields_num = mysql_num_fields($data);

echo "<table id ='appear2' border='1' style='border-collapse:collapse;font: 16px/20px Calibri, 
                Arial, Helvetica, sans-serif; background-color:white; ' width='auto'>";
        echo "<tr id='tblhead' style='text-align:center;'>";
        for($i=0; $i<$fields_num; $i++)
        {
                $field = mysql_fetch_field($data);
                echo "<td>{$field->name}</td>";
        }
        echo "</tr>\n";
        while($row = mysql_fetch_row($data))
        {
                echo "<tr>";
                foreach($row as $cell)
                echo "<td>$cell</td>";
                echo "</tr>\n";
        }

在此之后,ajax将获得参数res和数据。所有表都可以显示,但结果是在一个div内同时显示两个表。

ajax成功函数传递了三个参数:

Function( PlainObject data, String textStatus, jqXHR jqXHR )
从服务器返回的数据,根据dataType参数格式化;描述状态的字符串;以及jQuery1.4.x中的jqXHR,XMLHttpRequest对象

ajax请求的结果将是一个字符串,如:…50…1-100。。。如你所见

因此,我建议您发送两个ajax请求来获取数据。 如果必须这样做,可以这样做:

$("#qtycheck").html(res.substring(0, res.indexOf("<table>",1)));
$("#rangecheck").html(res.substring(res.indexOf("<table>",1)));

但这不是一个好办法。两个ajax请求更好

这可能是因为服务器端返回值。您是否将结果作为数组返回?是否打印了数据和res变量?它们都有什么价值?请先检查。@所有人都可以看到我更新的帖子。实际结果显示在表内。我试图将表分成两个div。但这两个表都只显示在一个id.res中,数据来自不同的查询。不同的查询意味着什么?我认为服务器的响应是一个字符串,这是函数中的第一个参数。我不知道它来自哪里。但我认为您可以使用数据。拆分\n;将50和1-100分开。然后你可以用不同的方式展示它们,希望能对你有所帮助
$("#qtycheck").html(res.substring(0, res.indexOf("<table>",1)));
$("#rangecheck").html(res.substring(res.indexOf("<table>",1)));