Ajax的get和post请求
1.get请求
function () { //向服务器请求 时间
//1.创建异步对象(小
浏览器)
var xhr = new
//2.设置参数,true表示使用异步模式
xhr.open("get", "GetTime.ashx?name= Mr靖", true);
//3.让get请求不从浏览器获取缓存数据
xhr.setRequestHeader("If-Modified-Since","0");
//3.设置回调函数
xhr.onreadystatechange = function ()
{
//3.1当完全接收完响应报文后 并且 响应状态码为200的时候
if (xhr.readyState == 4 && xhr.status == 200)
{
//3.2获取相应报文体内容
var res = xhr.responseText;
alert(res);
}
};
//4.发送异步请求
xhr.send(null);
}
2.post请求
function ()
{
//向服务器请求 时间
//1.创建异步对象(小浏览器)
var xhr = new
//2.设置参数
xhr.open("post", "GetTime.ashx", true);
//3.设置 请求 报文体 的 编码格式(设置为 表单默认编码格式)
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//4.设置回调函数
xhr.onreadystatechange = function ()
{
//3.1当完全接收完响应报文后 并且 响应状态码为200的时候
if (xhr.readyState == 4 && xhr.status == 200)
{
//3.2获取相应报文体内容
var res = xhr.responseText;
alert(res);
}
};
//5.发送异步请求"name=Mr靖"
//5.1格式:直接拼接字符串 key=value&key1=value2
xhr.send("name=Mr靖&age=18");
};
原标题:Ajax的get和post请求
关键词:ajax
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。
洛杉矶海外仓地址:https://www.goluckyvip.com/tag/95730.html
盘古海外仓:https://www.goluckyvip.com/tag/95731.html
第三方海外仓地址:https://www.goluckyvip.com/tag/95732.html
福冈海外仓:https://www.goluckyvip.com/tag/95734.html
巴西海外仓推荐:https://www.goluckyvip.com/tag/95737.html
云顶海外仓:https://www.goluckyvip.com/tag/95738.html
桂林酒店销售多少钱 桂林旅游宾馆价格:https://www.vstour.cn/a/410227.html
十里银滩旅游攻略玩什么住哪里怎么去?:https://www.vstour.cn/a/410228.html