weixin_33697898 2016-01-23 21:20 采纳率: 0%
浏览 27

HTML表单:打印php结果

I am trying to create a form that show a table obtain from a databse. I am following the tutorial about AJAX from the w3school and let me give my example:

I have a php file that print a table as a result of a database request with two variable x and y. If I put in my favorite navigator: localhost/list.php?x=0&y=0 it print a nice table... But what I want is to obtain x and y by a form I write more or less as in the turorial a index.html file:

<!DOCTYPE html>
<html>
<head>

<script>
function loadList() {
  var xhttp;    
  var x = document.getElementById("x").value;
  var y = document.getElementById("y").value;
  xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      document.getElementById("table").innerHTML = xhttp.responseText;
    }
  };
  xhttp.open("GET", "list.php?x="+x+"&y="+y, true);
  xhttp.send();
}
</script>

</head>
<body>

<form action="">
    <input type="text" id="x"> <br> 
    <input type="text" id="y"> <br>
    <input type="button" value="Find" onclick="loadList()">
</form>

<div id="table"> </div>

</body>
</html>

I would like that my form write the result (forexample when x=0 and y=0) of the list.php file in the div="table" at the end after the form! But... It does not works and I cannot resolve my problem.

Thanks in advance for your help!!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度