繁体   English   中英

我想使用 ajax 和 php 以表格形式检索数据

[英]I want to retrive data in tabular form using ajax and php

我写了以下代码

<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-    scale=1.0">
        <title>contact.dat</title>
      <body>
      <div id="demo">
    <h2>Retrive data by ajax</h2>
    <button type="button" onclick="printdata()">Retrive data</button>
    </div>
    
    <script>
    function printdata() {
      const xhttp = new XMLHttpRequest();
      xhttp.onload = function() {
        document.getElementById("demo").innerHTML +=this.responseText;
      }
      xhttp.open("GET", "contact.dat");
      xhttp.send();
    }
    </script>
      </body>
    
    <?php
    
    $fp = fopen('contact.dat', 'r');
    echo "<table border=1>";
    echo "<tr><th>Sr. No.</th><th>Name</th><th>Residence No.</th><th>Mob.
    no.</th><th>Address</th></tr>";
    while ($row = fscanf($fp, "%s %s %s %s %s")) {
        echo "<tr>";
        foreach ($row as $r) {
            echo "<td>$r</td>";
        }
        echo "</tr>";
    }
    echo "</table>";
    fclose($fp);
    ?>
    
    </html>

它向我展示这个输出 我想在单击按钮时显示数据。 我是 JavaScript 和 PHP 的新手。 有什么方法可以执行类似的操作

if(isset(printdata();))

然后运行php代码块???

这是错误的

/usr/bin/env /opt/jdk17/bin/java .... java.ASG6Ba 

您尝试执行的文件可能是ASG6Ba.java

提供的以ASG6Ba结尾的文件java.ASG6Ba对执行 java 没有意义。

此外java是 java 中包的禁止名称,由于提供的文件是java.ASG6Ba ,java 认为java是包名,然后跟在类名ASG6Ba 这是引发错误的具体原因。

禁止包名:java

这也在第 6.1 章的 java 文档中进行了描述

包或模块名称的第一个组件不能是标识符 java 以标识符 java 开头的包和模块名称是为 Java SE 平台的包和模块保留的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM