我有这个功能来访问 DeepL API
function translator(inputText){
var url = "https://api-free.deepl.com/v2/translate";
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.status);
console.log(xhr.responseText);
}
};
var data = "auth_key=123456x&text="+inputText+"&target_lang=EN";
xhr.send(data);
}
我想将返回的响应存储为字符串。这个怎么做?