1 回答

TA貢獻1804條經驗 獲得超2個贊
您的意思是您只想獲取數據而不發送任何稱為 http get 請求的數據,您可以按以下方式進行操作。
function get(url)
{
var xm = new XMLHttpRequest();
// false for synchronous
xm.open("GET",url,false);
xm.send(null);
return xm.responseText;
}
console.log(get('your Url'));
您需要指定 Http 端點(后端)的 url。
如果您正在發出異步請求,那么下面的代碼有效,,
function get(theUrl, callback)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
// true for asynchronous
xmlHttp.open("GET", theUrl, true);
xmlHttp.send(null);
}
get('your url',(responseText)=>{
console.log(responsetext);
});
- 1 回答
- 0 關注
- 109 瀏覽
添加回答
舉報