如何使用 javascript 从 php 站点读取文本


How can I read a text from a php site with javascript

我的php网站会回显一个数字。现在我想用JavaScript阅读内容。我该怎么做。

你可以用jQuery执行以下操作:

$.get("http://www.myawesomephppage.com/page.php", function(data) {
  alert(data);
});

或者没有jQuery:

var con = new XMLHttpRequest();
con.onreadystatechange = function() {
    if (con.readyState == 4 && con.status == 200) {
        alert(con.responseText);
    }
};
con.open("GET", "http://www.myawesomephp.com/mypage.php", true);
con.send();