您好,欢迎来到尔游网。
搜索
您的当前位置:首页post和get传参(重点)

post和get传参(重点)

来源:尔游网

在使用ajax方法进行数据交互的时候,会用到open方法,其中的第一个参数有 post和get两种传参方式,有一定的区别

get请去的传参数  在网址中拼接参数 第一个参数用?  后面的用&  每一对参数用=连接

get请求传输的数据不安全 但是它传输比较快

post请去的传参数  在send函数中传输  会把数据打包到请求体中,会加密变成暗文  就比较安全

post 传数据的方式比get慢

function get1 () {

                var xhr=new XMLHttpRequest()

                xhr.open("GET","http://192.168.5.109:8081/ajax1?type=3&count=20",true)

                xhr.send()

                xhr.onreadystatechange=function  () {

                    if(xhr.readyState==4){

                        console.log(xhr.responseText)

                    }

                }

            }

function post1 () {

                var xhr=new XMLHttpRequest()

                xhr.open("POST","http://192.168.5.109:8081/ajax2?type=3&count=20",true)

                xhr.send("pwd=abc123&userid=12345")

                xhr.onreadystatechange=function  () {

                    if(xhr.readyState==4){

                        console.log(xhr.responseText)

                    }

                }

            }

在route.js中,方法这样用

ajax2(req,res){

        if(req.method=="POST"){

            console.log(req.url)

            var msg="";

            req.on("data",(data)=>{

                msg+=data

            })

            req.on("end",()=>{

                console.log(msg)

            })

        }

        res.end('{"msg":"ajax2的数据"}')

    }

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- axer.cn 版权所有 湘ICP备2023022495号-12

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务