我正在尝试使用带有post方法的AJAX将用户名和密码发送到php文件。如何检索字段
16lz
2021-01-22
How to access these variables ? I'm trying to retrieve username and password in php files, But, it says Undefined index username if I use $_POST['Username'}
如何访问这些变量?我正在尝试在php文件中检索用户名和密码,但是,如果我使用$ _POST ['Username'},它会显示未定义的索引用户名
<script>
var a = new XMLHttpRequest();
a.onreadystatechange = function(){
if (a.readyState==4 && a.status==200) {
ajaxFinished = true;
alert(a.responseText);
}
else {
}
}
a.open("post","php/psswd.php",true);
a.send('"Username="+document.getElementByNames("Username")+"&Password="+getElementByNames("Password")'); // posting username and password
</script>
How to retrieve these fields in php file ?
如何在php文件中检索这些字段?
3 个解决方案
#1
1
I found out the answer myself, the problem was that, a.setRequestHeader("Content-type","application/x-www-form-urlencoded"); needs to be added. And document.getElementsByName('xyz') returns nodeList, but not perticular node, We need to traverse that nodeList.
我自己找到了答案,问题是,a.setRequestHeader(“Content-type”,“application / x-www-form-urlencoded”);需要添加。而document.getElementsByName('xyz')返回nodeList,但不返回特定节点,我们需要遍历那个nodeList。
更多相关文章
- 在CSDN下载资源,扣了积分,下载的是一个404页面的html文件
- html5结合flash实现视频文件在所有主流浏览器兼容播放
- iis aspx常见错误 HTTP 错误 404 - 文件或目录未找到。
- 急死我了!我以前用DREAMWEAVER编写的HTML文件突然变成乱码了!!!
- html页面输出pdf格式文件(一步步很详细)
- commons-fileupload文件上传、下载
- Eclipse中以html格式高亮显示velocity文件
- 将PHP代码添加到.html文件
- 性能权衡 - CSS效率,CSS文件大小,HTML文件大小