zoukankan      html  css  js  c++  java
  • 原生Get请求和Post请求

    get()请求

    function loadXMLDoc()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
    }

    xmlhttp.open("get","url",true);
    xmlhttp.send();

    }

    post()请求

    function loadXMLDoc()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
    }
    xmlhttp.open("POST","/ajax/demo_post2.asp",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send("fname=Bill&lname=Gates");
    }

    两者之间的区别     

    get()

    1.存放位置:请求放入请求行中   url后

    2.长度限制:2Kb

    3.效率:相对高

    4.只应用于取回数据

    post()

    1.存放位置:请求放入请求体中

    2.长度限制:理论上没有长度限制

    3.效率:相对低

    4.安全性:相对于get()高一些  但两者都没有绝对的安全

     

  • 相关阅读:
    Datatable导出到Excel
    C# 连接EXCEL和ACCESS字符串2003及2007版字符串说明
    C#-读取写入Excel
    简易的命令行入门教程:
    日志记录
    python环境管理器的选择
    go语言的模块处理
    pip 使用国内源 安装类库
    go 实现单链表并使用一种常规实现翻转,一种使用递归实现翻转
    数据库产品选型
  • 原文地址:https://www.cnblogs.com/sw91092/p/7504559.html
Copyright © 2011-2022 走看看