Answer the question
In order to leave comments, you need to log in
Why doesn't my code created on XMLHttpRequest work?
Here is the code
<script>
function Clickptpip(Element) {
var xhr = new XMLHttpRequest();
xhr.open('POST', 'test2.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
var body = 'url=' + encodeURIComponent(url) +
'&url2=' + encodeURIComponent(url2) +
'&urlsite=' + encodeURIComponent(urlsite) +
'&text=' + encodeURIComponent(text) +
'&referer=' + encodeURIComponent(referer) ;
xhr.send(body);
xhr.onreadystatechange = function() { // Ждём ответа от сервера
if (xhr.readyState == 4) { // Ответ пришёл
if(xhr.status == 200) { // Сервер вернул код 200 (что хорошо)
document.getElementById("otvet").innerHTML = xhr.responseText; // Выводим ответ сервера
}
}
};
}
</script>
<div>
<form>
<input type="text" name="urlsite" id="a" value="test" />
<br />
<input type="text" name="b" id="b" />
<br />
<input type="button" value="Вывод" onclick="Clickptpip(this);" />
</form>
<p>Ответ сервера <span id="otvet"></span></p>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question