首页 > 其他分享 >数据请求 ajax axios

数据请求 ajax axios

时间:2022-12-05 10:22:42浏览次数:43  
标签:function axios console 请求 url res ajax log

let url = "https://www.fastmock.site/mock/39aa306dc9dec321fb0237a30b3040d2/api"

// 使用jquery ajax 获取数据
$.ajax({
    type:"get",             //请求方式
    url:url+"/newList",     //请求地址
    success:function(res){  //请求成功返回的回调
        console.log(res);    //请求成功得到的数据
    },
    error:function(){        //请求失败的回调
        console.log("请求失败")
    }
})


$.ajax({
    type:"POST",
    url:url+"/login",
    data:{                    //请求需要用到的参数
        username:'admin',
        password:'123456'
    },
    success:function(res){
        console.log(res);
    },
    error:function(){
        console.log("请求失败")
    }
})

$.ajax({
    type:"put",
    url:url+"/change",
    data:{
        username:'ghahgah',
        password:'456'
    },
    success:function(res){
        console.log(res);
    },
    error:function(){
        console.log("请求失败")
    }
})



// 使用axios 获取数据
axios({
    method: 'get',            
    url:url+"/newList",
}).then(res=>{            //请求成功得到的数据
    console.log(res)
}).catch(function(err){    //请求失败的回调
    console.log("请求失败")
})

axios({
    method: 'post',
    url:url+"/login",
    data:{                    //请求需要用到的参数
        username:'admin',
        password:'123456'
    }
}).then(res=>{
    console.log(res)
}).catch(function(err){
    console.log("请求失败")
})


axios({
    method:'put', 
    url:url+"/change",
    data:{
        username:'admin',
        password:'789'
    }
}).then(res=>{
    console.log(res)
}).catch(function(err){
    console.log("请求失败")
})

 

标签:function,axios,console,请求,url,res,ajax,log
From: https://www.cnblogs.com/wubaiwan/p/16951590.html

相关文章

  • Http、Https简介和Session、token的请求流程
    Http    Http(超文本输出协议)是一种分布式、协作式和超媒体信息系统的应用层协议,它通常运行在TCP之上,因特网应用最广泛的便是Http协议,所有www都遵循这个标准。主......
  • Angular HttpClient 接收、发送 请求带 Cookie
    前言:angular客户端请求Webapi获取cookie,cooike设置一部分信息。才发现我以前使用angular发送http请求还从来没看到过接收、发送Cookie。其实接收、发送请求......
  • Request_获取请求参数中文乱码问题处理以及请求转发
    Request_获取请求参数中文乱码问题处理中文乱码问题:get方式:tomcat8已经将get方式乱码问题解决了post方式:会乱码解决:在获取参数前,设置request的编码:r......
  • django学习笔记-请求与响应
    1.请求与响应deftest(request):#获取请求方法print(request.method)#获取get的url请求参数print(request.GET)#获取post请求体参数pri......
  • Request_获取请求参数通用方式介绍以及方式演示
    Request_获取请求参数通用方式介绍以及方式演示获取请求参数通用方式:无论get还是post请求方式都可以使用下列方法来获取请求参数1.StringgetParameter(Stringname......
  • springboot03(请求和响应)
    一、@RequestMapping("/user"):请求映射路径的解析:总结:一个"公共"的请求路径"前缀"1.1代码块解析:有@RequestMapping("/user")和@RequestMapping("/save")/@Reques......
  • Request_请求头数据以及请求体的数据
    Request_请求头数据以及请求体的数据获取请求头数据方法:1.(*)StringgetHeader(Stringname):通过请求头的名称获取请求头的值2.Enumeration<Strin......
  • Request_获取请求行数据_方法介绍以及代码演示
    Request_获取请求行数据_方法介绍以及代码演示request功能:获取请求消息获取请求行数据GET/demo3?name=zhangsanHTTP/1.1......
  • axios二次封装
    https://blog.csdn.net/weixin_54930261/article/details/126658948?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIS......
  • Spring MVC请求地址映射详解:HandlerMapping
    1HandlerMapping介绍HandlerMapping是SpringMVC的核心组件之一,用来保存request-handler之间的映射。简单来说,request指的是请求地址(还包括请求方法等),handler指的是Cont......