JQuery------.load()从服务器获取数据并加载到某个类的方法

注意:需要在../Content/asf.txt路径下加入文件

html

<button class="Btn">按钮</button>

js

参数意义:

  • responseTxt - 包含调用成功时的结果内容
  • statusTXT - 包含调用的状态
  • xhr - 包含 XMLHttpRequest 对象
$(document).ready(function () {
    $(".Btn").click(function () {
        $(this).load("../Content/asf.txt", function (responseTxt, statusTxt, xhr) {
            if (statusTxt == "success") {
                alert("外部内容加载成功!");
                alert(responseTxt);
            }
            if (statusTxt == "error")
                alert("Error: " + xhr.status + ": " + xhr.statusText);
        });
    });

});
原文地址:https://www.cnblogs.com/tianhengblogs/p/5983729.html