Home > Backend Development > PHP Tutorial > html5中 FormData api ajax使用的有关问题

html5中 FormData api ajax使用的有关问题

WBOY
Release: 2016-06-13 11:57:26
Original
1171 people have browsed it

html5中 FormData api ajax使用的问题
各位朋友看下面的代码:

<br /><!DOCTYPE html><br /><html lang="zh"><br /><head><br />    <meta charset="utf-8"><br />    <title>html5 ajax测试</title><br /><script type="text/javascript"><br />function _send()<br />{<br />    var fm = document.getElementById('tform');<br />    var fd = new FormData(fm);    //把表单的文档对象给传过去<br />    var xhr = new XMLHttpRequest();<br />    xhr.open('POST', './test_post.php', true);<br />    xhr.onreadystatechange = function ()<br />    {<br />        if (this.readyState == 4)<br />        {<br />            document.getElementById('debug').innerHTML = this.responseText;         <br />        }<br />        //document.getElementById('debug').innerHTML = this.readyState;<br />    }<br />    xhr.send(fd);<br />}<br /></script><br /></head><br /><body><br /><form id="tform"><br /><p>用户名:<input type="text" name="username" /></p><br /><p>年龄:<input type="text" name="age" /></p><br /><p>邮箱:<input type="text" name="email" /></p><br /><p>性别:<input type="text" name="gender" /></p><br /><p><input type="submit" value="ajax发送" onclick="_send();"></p><br /></form><br /><div id="debug"><br /></div><br /></body><br /></html><br />
Copy after login

我的test_post.php中的代码是:
<br /><?php<br />print_r($_POST);<br />?><br />
Copy after login

在我的表单中正常输入数据后,点击提交,为什么我的:



中没有显示test_post.php中的数据,求解啊!
------解决方案--------------------
第十行的错了, new的new FormData 是没有参数的,然后利用生成的对象append 数据
------解决方案--------------------

应为
return _send();">
_send 应返回 false

button" value="ajax发送" onclick="_send();">
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template