如何将此XHR变为提取? [英] How can I get this XHR into a fetch?
本文介绍了如何将此XHR变为提取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法让它发挥作用。描述整个项目很复杂,因为它只有10个文件。
如果你能让它工作我真的很感激。
function getText(){
var $ a = document .getElementById(' text' )。值;
xhr = new XMLHttpRequest();
xhr.open(' POST', ' chatdb.php', true );
xhr.setRequestHeader(' content-type',' application / x-www-form-urlencoded');
xhr.send(' chat =' + $ a);
xhr.onreadystatechange = function (){
if (xhr.responseText) {
// document.getElementById('chatarea')。innerHTML = xhr.responseText;
}
}
}
我尝试了什么:
我试过这个:
function getText(){
var a = document .getElementById(' text')。value;
fetch(' chatdb.php',{method:' post'})
.then(response => response.text())
.then( responseText => {
document .getElementById(' text')。innerHTML = responseText;
})
。 catch (控制台跨度> .error);
}
解决方案
a = document .getElementById(< span class =code-string>' text')。value;
xhr = new XMLHttpRequest();
xhr.open(' POST', ' chatdb.php', true );
xhr.setRequestHeader(' content-type',' application / x-www-form-urlencoded');
xhr.send(' chat =' +
< BLOCKQUOTE>一);
xhr.onreadystatechange = function (){
if (xhr.responseText) {
// document.getElementById('chatarea')。innerHTML = xhr.responseText;
}
}
}
我尝试了什么:
我试过这个:
function getText(){
var a = document .getElementById(' text')。value;
fetch(' chatdb.php',{method:' post'})
.then(response => response.text())
.then( responseText => {
document .getElementById(' text')。innerHTML = responseText;
})
。 catch (控制台跨度> .error);
}
您没有发送POST
数据:
function getText(){
var a = document .getElementById(' text' )。值;
fetch(' chatdb.php',{
method:' POST',
header:{ Content-Type: application / x-www -form-urlencoded},
body: chat = + encodeURIComponent(a)
})
.then(response => response.text())
.then(responseText => {
document .getElementById(' text')。innerHTML = responseText;
})
。 catch ( console .error);
}
I Can't get it to work. It is complicated to describe the whole project since it's 10 files php only.
If you could get this to work i would really appreciate it.
function getText() {
var $a = document.getElementById('text').value;
xhr = new XMLHttpRequest();
xhr.open('POST' , 'chatdb.php',true);
xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
xhr.send('chat='+$a);
xhr.onreadystatechange=function(){
if (xhr.responseText){
// document.getElementById('chatarea').innerHTML=xhr.responseText;
}
}
}
What I have tried:
I've tried this:
function getText(){
var a = document.getElementById('text').value;
fetch ('chatdb.php', {method: 'post'})
.then (response => response.text())
.then (responseText => {
document.getElementById('text').innerHTML = responseText;
})
.catch (console.error);
}
解决方案
a = document.getElementById('text').value; xhr = new XMLHttpRequest(); xhr.open('POST' , 'chatdb.php',true); xhr.setRequestHeader('content-type','application/x-www-form-urlencoded'); xhr.send('chat='+
a); xhr.onreadystatechange=function(){ if (xhr.responseText){ // document.getElementById('chatarea').innerHTML=xhr.responseText; } } }
What I have tried:
I've tried this:
function getText(){ var a = document.getElementById('text').value; fetch ('chatdb.php', {method: 'post'}) .then (response => response.text()) .then (responseText => { document.getElementById('text').innerHTML = responseText; }) .catch (console.error); }
You're not sending thePOST
data:
function getText(){ var a = document.getElementById('text').value; fetch ('chatdb.php', { method: 'POST', headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: "chat=" + encodeURIComponent(a) }) .then (response => response.text()) .then (responseText => { document.getElementById('text').innerHTML = responseText; }) .catch (console.error); }
这篇关于如何将此XHR变为提取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文