Php 打印ajax响应,即打印

Php 打印ajax响应,即打印,php,jquery,ajax,Php,Jquery,Ajax,如果你可以编辑标题,请做 修订版 这是main.php $(document).ready(function(e) { $("#searchForm").submit(function(e) { e.preventDefault(); $("#result").load("process_search.php",{"searchKeyID":$("#searchKeyID").val()}, function(respo

如果你可以编辑标题,请做

修订版 这是main.php

$(document).ready(function(e)
 {
      $("#searchForm").submit(function(e)
       {
            e.preventDefault();
            $("#result").load("process_search.php",{"searchKeyID":$("#searchKeyID").val()}, function(response,status)
             {
                  alert(response);
             });

       });
 });


<body> 
   <form id="searchForm" method="post">
   <table>
      <tr>
          <td> <input type="text" id="searchKeyID" /> </td>
          <td> <input type="submit" id="searchButtonID" value="Search" /> </td>
      </tr>
   </table>
   </form>
<div id="result"></div>
</body>
print\r将以无组织的方式显示数组的内容。我完全知道,我可以以一种有组织的方式在process.php中回显它,以便它在main.php中显示为一个适当的数据组织。但是,我希望数组/obj返回到main,并且在main中,进行有组织的打印。这就是我放的地方?????在我的代码中

我该怎么做

我遇到了这个。让我更加困惑。我不知道得到57票的答案是怎么回事。如何打印第二个索引。我按原样复制了代码并运行了它。上面印着丹斯基和马斯基。它如何知道要使用哪个索引/val

如果我输入警报(响应);它可以代替问号。我看到整个obj/阵列组织得很好。我确实看到了打印数组的主题,但不像记录。。。我忘了在jquery:D中查找打印记录的站点,我会马上查找


编辑:我了解了我包含的链接中的代码是如何工作的。

我建议使用而不是$.load()。如果这样做,请尝试使用以下代码:

$(document).ready(function(e) {
    $("#searchForm").submit(function(e) {
        e.preventDefault();
        $.post("process_search.php", {searchKeyID:$("#searchKeyID").val()},function (data) {
            // data is now the same Array as the one you had in process_search.php ; You can now work with it as you like ; e.g.:
            alert(data[0]);
        },"json");
    });
 });

<body> 
    <form id="searchForm" method="post">
        <table>
            <tr>
                <td> <input type="text" id="searchKeyID" /> </td>
                <td> <input type="submit" id="searchButtonID" value="Search" /> </td>
            </tr>
        </table>
    </form>
    <br />
    <br />
    <div id="result"></div>
</body>
致:


我建议使用而不是$.load()。如果这样做,请尝试使用以下代码:

$(document).ready(function(e) {
    $("#searchForm").submit(function(e) {
        e.preventDefault();
        $.post("process_search.php", {searchKeyID:$("#searchKeyID").val()},function (data) {
            // data is now the same Array as the one you had in process_search.php ; You can now work with it as you like ; e.g.:
            alert(data[0]);
        },"json");
    });
 });

<body> 
    <form id="searchForm" method="post">
        <table>
            <tr>
                <td> <input type="text" id="searchKeyID" /> </td>
                <td> <input type="submit" id="searchButtonID" value="Search" /> </td>
            </tr>
        </table>
    </form>
    <br />
    <br />
    <div id="result"></div>
</body>
致:


我建议使用而不是$.load()。如果这样做,请尝试使用以下代码:

$(document).ready(function(e) {
    $("#searchForm").submit(function(e) {
        e.preventDefault();
        $.post("process_search.php", {searchKeyID:$("#searchKeyID").val()},function (data) {
            // data is now the same Array as the one you had in process_search.php ; You can now work with it as you like ; e.g.:
            alert(data[0]);
        },"json");
    });
 });

<body> 
    <form id="searchForm" method="post">
        <table>
            <tr>
                <td> <input type="text" id="searchKeyID" /> </td>
                <td> <input type="submit" id="searchButtonID" value="Search" /> </td>
            </tr>
        </table>
    </form>
    <br />
    <br />
    <div id="result"></div>
</body>
致:


我建议使用而不是$.load()。如果这样做,请尝试使用以下代码:

$(document).ready(function(e) {
    $("#searchForm").submit(function(e) {
        e.preventDefault();
        $.post("process_search.php", {searchKeyID:$("#searchKeyID").val()},function (data) {
            // data is now the same Array as the one you had in process_search.php ; You can now work with it as you like ; e.g.:
            alert(data[0]);
        },"json");
    });
 });

<body> 
    <form id="searchForm" method="post">
        <table>
            <tr>
                <td> <input type="text" id="searchKeyID" /> </td>
                <td> <input type="submit" id="searchButtonID" value="Search" /> </td>
            </tr>
        </table>
    </form>
    <br />
    <br />
    <div id="result"></div>
</body>
致:


好的,首先,谢谢你对僵尸代码的帮助。他的回答促成了我达成的解决方案

我有从数据库中检索到的记录。我想在div中以表的形式打印这些内容。有两种解决方案:在process_search.php中回显该表,它将出现在mainpage.php中使用load()方法的div容器中。第二种解决方案是接收mainpage.php中的记录,并使用jquery动态创建一个表

第一个解决方案很简单。这是我遇到麻烦的第二个。我正在“试验”

下面是使用我自己的代码的解决方案

<script>
$(document).ready(function(e)
 {
     $("#searchForm").submit(function(e)
      {
          e.preventDefault();
          //linebegin
          $("#result").load("process_search.php", {searchKeyID:$("#searchKeyID").val()}, function (response,status)
           {
               var x = $.parseJSON(response);  //1
               var table = $('<table></table>');
               for (i = 0; i < x.length; i++)
                {
                   var row = $('<tr></tr>').text(x[i].email);
                   table.append(row);
                }

               $('#result').html(table); //3
           }); //lineend
      });
 });
</script>

<body>
 <form id="searchForm" method="post">
 <table>
    <tr>
       <td> <input type="text" id="searchKeyID" /> </td>
       <td> <input type="submit" id="searchButtonID" value="Search" /> </td>
    </tr>
 </table>
 </form>
 <div id="result"></div>
</body>
我向您展示了“丑陋”数组,以及JSON中的数组看起来如何更好、更容易使用。为了适应僵尸的代码,如果我想打印数据以查看“更容易更好”的内容,我会键入
alert(JSON.stringify(data))

如果我只想看第一张唱片
alert(JSON.stringify(数据[0])

在//5中,我正在打印对象中第一条记录的电子邮件值。 我可以说data[0],它将打印整个数组。因为我返回了一条记录,所以它是data0。如果我有更多的记录,那么data1 data2等等

您可以使用主题中的答案打印表格。你需要做一些小改动


我希望大家都明白了这一点。

好的,首先,感谢您对僵尸代码的帮助。他的回答促成了我达成的解决方案

我有从数据库中检索到的记录。我想在div中以表的形式打印这些内容。有两种解决方案:在process_search.php中回显该表,它将出现在mainpage.php中使用load()方法的div容器中。第二种解决方案是接收mainpage.php中的记录,并使用jquery动态创建一个表

第一个解决方案很简单。这是我遇到麻烦的第二个。我正在“试验”

下面是使用我自己的代码的解决方案

<script>
$(document).ready(function(e)
 {
     $("#searchForm").submit(function(e)
      {
          e.preventDefault();
          //linebegin
          $("#result").load("process_search.php", {searchKeyID:$("#searchKeyID").val()}, function (response,status)
           {
               var x = $.parseJSON(response);  //1
               var table = $('<table></table>');
               for (i = 0; i < x.length; i++)
                {
                   var row = $('<tr></tr>').text(x[i].email);
                   table.append(row);
                }

               $('#result').html(table); //3
           }); //lineend
      });
 });
</script>

<body>
 <form id="searchForm" method="post">
 <table>
    <tr>
       <td> <input type="text" id="searchKeyID" /> </td>
       <td> <input type="submit" id="searchButtonID" value="Search" /> </td>
    </tr>
 </table>
 </form>
 <div id="result"></div>
</body>
我向您展示了“丑陋”数组,以及JSON中的数组看起来如何更好、更容易使用。为了适应僵尸的代码,如果我想打印数据以查看“更容易更好”的内容,我会键入
alert(JSON.stringify(data))

如果我只想看第一张唱片
alert(JSON.stringify(数据[0])

在//5中,我正在打印对象中第一条记录的电子邮件值。 我可以说data[0],它将打印整个数组。因为我返回了一条记录,所以它是data0。如果我有更多的记录,那么data1 data2等等

您可以使用主题中的答案打印表格。你需要做一些小改动


我希望大家都明白了这一点。

好的,首先,感谢您对僵尸代码的帮助。他的回答促成了我达成的解决方案

我有从数据库中检索到的记录。我想在div中以表的形式打印这些内容。有两种解决方案:在process_search.php中回显该表,它将出现在mainpage.php中使用load()方法的div容器中。第二种解决方案是接收mainpage.php中的记录,并使用jquery动态创建一个表

第一个解决方案很简单。这是我遇到麻烦的第二个。我正在“试验”

下面是使用我自己的代码的解决方案

<script>
$(document).ready(function(e)
 {
     $("#searchForm").submit(function(e)
      {
          e.preventDefault();
          //linebegin
          $("#result").load("process_search.php", {searchKeyID:$("#searchKeyID").val()}, function (response,status)
           {
               var x = $.parseJSON(response);  //1
               var table = $('<table></table>');
               for (i = 0; i < x.length; i++)
                {
                   var row = $('<tr></tr>').text(x[i].email);
                   table.append(row);
                }

               $('#result').html(table); //3
           }); //lineend
      });
 });
</script>

<body>
 <form id="searchForm" method="post">
 <table>
    <tr>
       <td> <input type="text" id="searchKeyID" /> </td>
       <td> <input type="submit" id="searchButtonID" value="Search" /> </td>
    </tr>
 </table>
 </form>
 <div id="result"></div>
</body>
我向您展示了“丑陋”数组,以及JSON中的数组看起来如何更好、更容易使用。为了适应僵尸的代码,如果我想打印数据以查看“更容易更好”的内容,我会键入
alert(JSON.stringify(data))

如果我只想看第一张唱片
alert(JSON.stringify(数据[0])

在//5中,我正在打印对象中第一条记录的电子邮件值。 我可以说data[0],它将打印整个数组。因为我返回了一条记录,所以它是data0。如果我有更多的记录,那么data1 data2等等

您可以使用主题中的答案打印表格。你需要做一些小改动


我希望大家都明白了这一点。

好的,首先,感谢您对僵尸代码的帮助。他的回答促成了我达成的解决方案

我有从数据库中检索到的记录。我想在div中以表的形式打印这些内容。有两种解决方案:在process_search.php中回显该表,它将出现在mainpage.php中的div容器中,其中