2 回答

TA貢獻(xiàn)1805條經(jīng)驗 獲得超10個贊
這是一個不需要jquery的版本:
function insertPage() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
var element = document.createElement("div");
element.innerHTML = this.responseText;
document.body.appendChild(element);
};
xhttp.open("GET", "https://www.shizyab.ir/rand.php", true);
xhttp.send();
}
并運行此代碼:insertPage();

TA貢獻(xiàn)1784條經(jīng)驗 獲得超7個贊
您可以通過在 window.onload 上的腳本中使用帶有 jquery 的 ajax 調(diào)用來實現(xiàn)此目的: 假設(shè)你的 php 腳本返回一個 json 對象。
function getData(username, callback) {
var url = 'shizyab.ir/rand.php';
$.ajax({
url:(url),
type: 'GET',
dataType: 'json',
success: (data) => {
callback(data);
}
});
}
然后在callback函數(shù)中處理數(shù)據(jù)顯示。
- 2 回答
- 0 關(guān)注
- 200 瀏覽
添加回答
舉報