简体   繁体   English

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

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

I have written the following code我写了以下代码

<!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>

its showing me它向我展示这个输出 I want to show data when I click on the button.我想在单击按钮时显示数据。 I'm new in both JavaScript as well as PHP.我是 JavaScript 和 PHP 的新手。 is there any way to perform something like有什么方法可以执行类似的操作

if(isset(printdata();))

then run php code block???然后运行php代码块???

Here lies the wrong这是错误的

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

Probably the file that you try to execute is ASG6Ba.java .您尝试执行的文件可能是ASG6Ba.java

The provided file java.ASG6Ba with the ending ASG6Ba makes no sense for java to be executed.提供的以ASG6Ba结尾的文件java.ASG6Ba对执行 java 没有意义。

Also java is a prohibited name for packages in java and since the file provided is java.ASG6Ba , java thinks that java is a package name and then follows the class name ASG6Ba .此外java是 java 中包的禁止名称,由于提供的文件是java.ASG6Ba ,java 认为java是包名,然后跟在类名ASG6Ba This is the specific reason the error is thrown.这是引发错误的具体原因。

Prohibited package name: java禁止包名:java

This is also described in java documentation in chapter 6.1这也在第 6.1 章的 java 文档中进行了描述

The first component of a package or module name must not be the identifier java .包或模块名称的第一个组件不能是标识符 java Package and module names that start with the identifier java are reserved for packages and modules of the Java SE Platform以标识符 java 开头的包和模块名称是为 Java SE 平台的包和模块保留的

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

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