简体   繁体   English

ajax,没有jquery的普通javascript:将要作为GET数据发送到php的文本放在哪里?

[英]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.

相关问题 使用没有jQuery或Ajax的纯JavaScript将php值传递给模式 - Passing a php value to modal using plain javascript without jquery or ajax 如何将 socket_read 值获取为从 PHP websocket 中的 javascript 发送的纯文本 - how to get socket_read value to plain text sent from javascript in PHP websocket 通过 AJAX 使用没有 Jquery 的普通 Javascript 提交表单获取选中的单选按钮值 - Submit form via AJAX using plain Javascript without Jquery get checked radio button value 数据未从 jQuery AJAX 发送到 PHP - Data not being sent to PHP from jQuery AJAX PHP无法获取发送的Ajax数据 - PHP can't get ajax data sent AJAX请求php以获取由post / get发送的指定目录中服务器上文件的列表(WITHOUT JQUERY) - AJAX request to php for getting the list of the file on the server in the specified directory sent by post/get (WITHOUT JQUERY) 获取一个PHP文件以将文本/纯文本返回给AJAX调用 - Get a PHP file to return text/plain to AJAX call 通过纯 JavaScript(AJAX) 和 PHP 删除 SQL 数据 - Deleting SQL data via plain JavaScript(AJAX) and PHP 带有响应array []的jQuery Ajax PHP POST方法instad发送了数据。 如何获得发送值作为响应? - jQuery Ajax PHP POST method with response array[] instad sent data. How to get send values in response? jQuery Mobile使用不含AJAX和JavaScript的PHP提交 - jQuery Mobile submit with PHP without AJAX and JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM