Ajax如何在Wame服务器上工作? [英] How ajax working on wame server?

查看:68
本文介绍了Ajax如何在Wame服务器上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是第一次开始从w3schools网站学习ajax,我按步骤进行操作,试图使AJAX示例工作,但我无法使其工作.请问你能帮帮我吗 ?谢谢你.

Hi all I am first time starting to learn ajax from website w3schools, and I follow the step by step I'm trying to get an AJAX example working but i'm unable to get it working. could you help me please ? thanks you.

这是我的代码

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,

You can use ajax like this,

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

这篇关于Ajax如何在Wame服务器上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆