Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Ajax没有';刷新html页面_Php_Ajax - Fatal编程技术网

Php Ajax没有';刷新html页面

Php Ajax没有';刷新html页面,php,ajax,Php,Ajax,我不熟悉编码。我想刷新一下 “测试文本” 在HTML div id='result'中 到 “或者别的什么” 在data.php文件中 我不明白为什么它不起作用,因为我从视频课程中复制了那个代码。我正在Microsoft WebMatrix上运行这些页面。 我试图安装XAMPP,但无法启动Apache服务器。所以我最终选择了WebMatrix。谢谢你帮助新手 HTML文件 <!DOCTYPE html> <html> <head> <ti

我不熟悉编码。我想刷新一下

“测试文本” 在HTML div id='result'中 到 “或者别的什么” 在data.php文件中

我不明白为什么它不起作用,因为我从视频课程中复制了那个代码。我正在Microsoft WebMatrix上运行这些页面。 我试图安装XAMPP,但无法启动Apache服务器。所以我最终选择了WebMatrix。谢谢你帮助新手

HTML文件

    <!DOCTYPE html>
<html>
<head>
    <title></title>
    <script>

     function ajax_request() {
         var xmlhttp = new XMLHttpRequest();

         xmlhttp.onreadystatechange = function () {
             if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                 var result = document.getElementById('result');
                 result.innerHTML = xmlhttp.responseText;

             }

         }
         xmlhttp.open('Get', 'data.php', true);
         xmlhttp.send();
     }

    </script>
</head>
<body>
    <button onclick="ajax_request">Click me</button>
    <div id='result'>Test text</div>
</body>
</html>
   <?php 
    $data = "Or something else";
    echo $data;

?>

函数ajax_request(){
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
var result=document.getElementById('result');
result.innerHTML=xmlhttp.responseText;
}
}
open('Get','data.php',true);
xmlhttp.send();
}
点击我
测试文本
PHP文件

    <!DOCTYPE html>
<html>
<head>
    <title></title>
    <script>

     function ajax_request() {
         var xmlhttp = new XMLHttpRequest();

         xmlhttp.onreadystatechange = function () {
             if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                 var result = document.getElementById('result');
                 result.innerHTML = xmlhttp.responseText;

             }

         }
         xmlhttp.open('Get', 'data.php', true);
         xmlhttp.send();
     }

    </script>
</head>
<body>
    <button onclick="ajax_request">Click me</button>
    <div id='result'>Test text</div>
</body>
</html>
   <?php 
    $data = "Or something else";
    echo $data;

?>

单击我
一定是

<button onclick="ajax_request();">Click me</button>
点击我
单击我
一定是

<button onclick="ajax_request();">Click me</button>
点击我

谢谢你,伙计!如此愚蠢的错误://我应该删除我的帖子/问题(错误是如此令人尴尬的愚蠢)还是版主会这么做?谢谢,伙计!如此愚蠢的错误://我应该删除我的帖子/问题(错误是如此令人尴尬的愚蠢)还是版主会这么做?