[英]ajax, plain javascript without jquery: where to put the text that will be sent as GET data to php?
In my HTML I have this line of code: 在我的HTML中,有以下代码行:
<td>Username:</td>
<td><input type="text" size="40" id="username" name="username" /></td>
<td><input type="button" value="check" onclick="checkExistenceUsername()" /></td>
<td id="result_of_checking"></td>
How I tell to ajax that he has to take the content of the tag with id "username"? 我如何告诉ajax,他必须接受ID为“ username”的标签的内容?
This is javascript: 这是javascript:
function checkExistenceUsername()
{ var xmlhttp; {var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("result_of_checking").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "check_existence.php", true);
xmlhttp.send();
} }
I think you would need something like this answer 我认为您将需要这样的答案
But instead of hard coded parameters you would need to add the input variable: 但是,您需要添加输入变量来代替硬编码的参数:
var params = "myvar="+encodeURIComponent(document.getElementById('username').value);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.