Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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
ajax如何在wame服务器上工作?_Ajax - Fatal编程技术网

ajax如何在wame服务器上工作?

ajax如何在wame服务器上工作?,ajax,Ajax,大家好,我是第一次从w3schools网站开始学习ajax的,我一步一步地学习,我试图让一个ajax示例工作,但我无法让它工作。你能帮我吗?谢谢你 这是我的密码 ajax.php <!DOCTYPE html> <html> <body> <div id="demo"><h2>Let AJAX change this text</h2></div> <button type="button" oncli

大家好,我是第一次从w3schools网站开始学习ajax的,我一步一步地学习,我试图让一个ajax示例工作,但我无法让它工作。你能帮我吗?谢谢你

这是我的密码

ajax.php

<!DOCTYPE html>
<html>
<body>

<div id="demo"><h2>Let AJAX change this text</h2></div>

<button type="button" onclick="loadDoc()">Change Content</button>

<script>
function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      document.getElementById("demo").innerHTML = xhttp.responseText;
    }
  };
  xhttp.open("GET", "ajax_info.txt", true);
  xhttp.send();
}
</script>

</body>
</html>

让AJAX更改此文本
更改内容
函数loadDoc(){
var xhttp=newXMLHttpRequest();
xhttp.onreadystatechange=函数(){
如果(xhttp.readyState==4&&xhttp.status==200){
document.getElementById(“demo”).innerHTML=xhttp.responseText;
}
};
open(“GET”,“ajax\u info.txt”,true);
xhttp.send();
}

您可以像这样使用ajax

<script>
function loadDoc() {
$.ajax({
            xhr: function() {
                var xhr = new window.XMLHttpRequest();
                //progress

                xhr.upload.addEventListener("progress", function(e) {
                    //progress value e
                    load_progress(e);
                }, false);
                return xhr;
            },
            type: "GET",
            url: "ajax_info.txt",
            success: function(msg) {
               //when success //200 ok
              document.getElementById("demo").innerHTML = msg;
            },
            error: function(jqXHR, textStatus, errorThrown) {
               //when error   
            }
        });
}
</script>

函数loadDoc(){
$.ajax({
xhr:function(){
var xhr=new window.XMLHttpRequest();
//进展
xhr.upload.addEventListener(“进度”,函数(e){
//进度值e
加载进度(e);
},假);
返回xhr;
},
键入:“获取”,
url:“ajax_info.txt”,
成功:功能(msg){
//当成功时//200 ok
document.getElementById(“demo”).innerHTML=msg;
},
错误:函数(jqXHR、textStatus、errorshown){
//出错时
}
});
}

添加一些
console.log
s,然后打开开发工具(通常是F12),这样您就可以看到发生了什么。如何在ajax中添加console.log:Dyou可以编写
console.log('loadDoc called')
var xhttp
之前。在
if
write
console.log(xhttp.readyState,xhttp.status)之前好的,谢谢你,兄弟,我会试试
ajax\u info.txt
文件中的内容??我正在从W3schoolsCLICC按钮中尝试此exmaple,您可以自己尝试。您需要创建
ajax\u info.txt
文件,并放入此文本,
AJAX不是一种新的编程语言。

AJAX是一种创建快速动态网页的技术。

并将其保存在您的文件根中我的文件AJAX在E:\wamp\www中,我正在创建AJAX\u info.txt,在E:\wamp\www中包含文本Hello world,但它仍然不起作用:(