JS中的Ajax操作实例,get方式和post方式对比
来源:互联网 发布:人工智能的利弊800字 编辑:程序博客网 时间:2024/06/16 00:13
AJAX有另外一个名字叫XML HTTP请求,是微软首先创建的。
get和post方式对比
Get方式
Post方式
function doRequestUsingGET(){
//1、创建XMLHttpRequest对象
if(window.ActiveXObject){
//IE5、IE6浏览器
var xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
}else if(window.XMLHttpRequest){
//其他浏览器
var xmlHttp = new XMLHttpRequest();
}
//2、设置回调函数
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState==4 && xmlHttp.status==200){
var responseDiv = document.getElementById(serverResponse); responseDiv.innerHTML = decodeURI(xmlHttp.responseText);
}
}
//3、创建连接
var queryString = “name1=value1&name2=value2”;
var url = “test.php”
var data = url+”?”+queryString;
xmlHttp.open("GET",data);
//4、发送数据
xmlHttp.send(null);
}
function doRequestUsingPOST(){
//1、创建XMLHttpRequest对象
if(window.ActiveXObject){
//IE5、IE6浏览器
var xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
}else if(window.XMLHttpRequest){
//其他浏览器
var xmlHttp = new XMLHttpRequest();
}
//2、设置回调函数
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState==4 && xmlHttp.status==200){
var responseDiv = document.getElementById(serverResponse); responseDiv.innerHTML = decodeURI(xmlHttp.responseText);
}
}
//3、创建连接
var queryString = “name1=value1&name2=value2”;
var url = “test.php”
xmlHttp.open("POST",url);
//4、设置HTTP请求头部
xmlHttp.setRequestHeader(“Content-Type”,”application/x-www-form-urlencoded”)
//5、发送数据
xmlHttp.send(queryString);
}
- JS中的Ajax操作实例,get方式和post方式对比
- AJAX中的POST与GET方式实例
- Ajax中的get与post方式区别
- ajax以get和post方式请求
- ajax实例---post方式
- ajax中的get方式和post方式传递的参数长度
- Ajax的Get方式和Post方式的详细解析
- Get方式和Post方式
- GET和POST方式
- javascript/js的ajax请求方式:GET与POST
- Ajax异步传输方式中的GET与POST
- Ajax中的get和post两种请求方式的用法
- Ajax中的get和post两种请求方式的用法
- Ajax中的get和post两种请求方式的异同
- Ajax中的get和post两种请求方式的异同
- Ajax中的get和post两种请求方式的异同
- Ajax中的get和post两种请求方式的异同
- Ajax中的get和post两种请求方式的异同
- 单例模式的七种写法
- 笔记一:递归
- 黑马程序员——Java入门重点知识点及环境变量设置
- 使用javax.mail.ja在javaEE5中出现异常
- 10603 Fill (BFS)
- JS中的Ajax操作实例,get方式和post方式对比
- LLVM (6) 11.5 一个目标可重定向的LLVM代码生成器
- Lowest Common Multiple Plus(杭电2028)
- 就从第一个简单的JAVA出发
- 各类硬盘接口总结
- Redraiment猜想2 (容斥)
- android实现圆形ImageView
- 链表创建
- ECC纠错算法