dsagzmosl32217092 2015-03-19 03:03
浏览 45
已采纳

你如何在PHP中使用echo在html中打印文本?

I am attempting to use php to print out a line of text onto a html file, but when I run the html, it merely prints the word undefined. How can I fix this? Here is the code:

HTML:

<html>
<head>
</head>
<body>
<script type="text/javascript">
var xmlhttp=new XMLHttpRequest();
var textinhtml=document.createElement("div");
var text=document.createTextNode(xmlhttp.open("GET","http://mikeyrichards.bugs3.com/test.php",true));
textinhtml.appendChild(text);
document.body.appendChild(textinhtml);
xmlhttp.send();
</script>
</body>  

PHP:

<?php
echo "Hello, World"
?>
  • 写回答

1条回答 默认 最新

  • dsh125986083 2015-03-19 03:19
    关注

    As commented your usage of XMLHttpRequest is wrong, you should check online example of it, like this example from the mozilla dev network

    Adapted to your script :

    <script type="text/javascript">
       var xmlhttp=new XMLHttpRequest();
       xmlhttp.onload = function() {
           var textinhtml=document.createElement("div");
           var text=document.createTextNode(this.responseText);
           textinhtml.appendChild(text);
           document.body.appendChild(textinhtml);
       }
       xmlhttp.open("GET","http://mikeyrichards.bugs3.com/test.php",true)
       xmlhttp.send();
    </script>
    

    this script does not account for the errors from the request. Please read the documentation to handle them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?