AJAX-----05XMLHttpRequest对象的用post方式进行ajax请求
2016-11-07 00:13
696 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <script> function createXHR(){ var xhr = null; if(window.XMLHttpRequest){ xhr = new XMLHttpRequest(); }else if(window.ActiveXObject){ xhr = new ActiveXObject("Microsoft.XMLHTTP"); } return xhr; } function reg(){ //制造xhr var xhr = createXHR(); //打开post链接 xhr.open('post','5.php',true); //收集表单数据 var user = document.getElementsByName('user')[0].value; var emali = document.getElementsByName('emali')[0].value; //test //alert('user='+user+'&emali='+emali); //post的必须要有这个头信息才可以 xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); //发送 xhr.send('user='+user+'&emali='+emali); //状态 xhr.onreadystatechange = function(){ if(this.readyState == 4 && this.status == 200){ alert(this.responseText); } } return false; } </script> <body> <form action="5.php" method="post" onsubmit="return reg();"> USER: <input type="text" name="user"> <span id="user"></span> <br> <br> EMAIL: <input type="text" name="emali"> <span id="emali"></span><br> <br> <input type="submit" value="OK"> </form> </body> </html>
<?php print_r($_POST);
效果如下所示:
相关文章推荐
- 原始ajax通过xmlHttpRequest对象的send()方法提交数据--Get方式和Post方式
- ajax中XMLHttpRequest对象的open()方法GET和POST方式区别
- jQuery的ajax()检验用户名;通过jQuery的load()/get()/post()方法实现;使用XMLHTTPRequest对象来进行AJAX的异步数据交互
- JS中使用XMLHttpRequest对象进行Ajax操作
- Ajax获取XmlHttpRequest对象的方法,兼容IE、火狐。用来与服务器进行通信。
- Ajax学习(一),获得XMLHttpRequest对象,进行初步异步交互(jquery.javascript)
- 使用xmlhttprequest对象来进行AJAX的异步数据交互
- XMLHTTPRequest对象进行AJAX的异步数据交互
- 使用jquery中的ajax进行post请求时,报错,提示[object XMLHttpRequest]
- Ajax简单应用示例: XMLHttpRequest对象实例化方式及调用
- Ajax核心对象-- XMLHttpRequest
- AJAX的核心XMLHttpRequest对象
- Ajax - XMLHttpRequest对象
- 为何XMLHttpRequest对象是AJAX的核心
- 用XMLHTTPRequest对象进行客户端验证
- Ajax与XMLHttpRequest对象
- AJAX中同时发送多个请求XMLHttpRequest对象处理方法
- Ajax - XMLHttpRequest对象的属性responseText
- AJAX客户端说明,XMLHttpRequest对象
- AJAX 学习笔记(1) XMLHttpRequest对象概述