以下是一個使用JavaScript從Ajax響應(yīng)中獲取特定變量的示例:
// 創(chuàng)建XMLHttpRequest對象
var xhttp = new XMLHttpRequest();
// 向服務(wù)器發(fā)送請求
xhttp.open("GET", "example.php", true);
xhttp.send();
// 在響應(yīng)準備就緒時調(diào)用函數(shù)
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// 解析響應(yīng)文本
var response = JSON.parse(this.responseText);
// 獲取特定變量
var variable = response.variable;
}
};