axios jquery ajax

axios @RequestBody

post

javascript 复制代码
axios.post('/vue/insert', this.newStudent)
                    .then(r => {
                    console.log('Student added successfully:', r);
                }).catch(e => {   console.error('There was an error adding the student!', e);     });

后端

java 复制代码
@RestController
@RequestMapping("/vue")
public class VueController {
    @PostMapping("/insert")
    String test(@RequestBody Map map){
        System.out.println(map);
        return "OK";
    }

}

jquery post JSON.stringify @RequestBody

ajax

javascript 复制代码
 $.ajax({
                      type:'post',
                      url:"vue/insert",
                      data: JSON.stringify(this.newStudent),
                      contentType:"application/json",
                  }).then(r=>{console.log(r)})

post

javascript 复制代码
 $.ajaxSetup({
                    headers: {
                        'Content-Type': 'application/json'
                    }
                });
                $.post('/vue/insert',JSON.stringify( this.newStudent)).then(r=>{
                        console.log("then:"+r)
                    }).fail(e=>{console.log("fail"+e)})

后端

java 复制代码
@RestController
@RequestMapping("/vue")
public class VueController {
    @PostMapping("/insert")
    String test(@RequestBody Map map){
        System.out.println(map);
        return "OK";
    }

}

jquery post @RequestParam

post

javascript 复制代码
 $.post('/vue/insert',this.newStudent).then(r=>{
                        console.log("post  then:"+r)
                    }).fail((a,b,c)=>{console.log(a)})

ajax

javascript 复制代码
$.ajax({
                      type:'post',
                      url:"vue/insert",
                      data: this.newStudent
                  }).then(r=>{console.log("ajaxthen:"+r)})

jquery get @RequestParam

get

javascript 复制代码
$.get('/vue/insert',this.newStudent).then(r=>{
                        console.log("get  then:"+r)
                    }).fail((a,b,c)=>{console.log(a)})
相关推荐
前端熊猫1 小时前
jQuery AJAX、Axios与Fetch
ajax·okhttp·jquery
北上ing2 小时前
同一页面下动态加载内容的两种方式:AJAX与iframe
前端·javascript·ajax
Jet_closer_burning7 小时前
axios封装
前端·javascript·vue.js·react.js·ajax
程序员沉梦听雨1 天前
OkHttp入门
okhttp
隐-梵1 天前
Android studio进阶开发(四)--okhttp的网络通信的使用
android·ide·okhttp·android studio
知识分享小能手1 天前
JavaScript学习教程,从入门到精通,XMLHttpRequest 与 Ajax 请求详解(25)
开发语言·javascript·学习·ajax·前端框架·css3·html5
知识分享小能手2 天前
JavaScript学习教程,从入门到精通,Ajax与Node.js Web服务器开发全面指南(24)
开发语言·前端·javascript·学习·ajax·node.js·html5
星之卡比*2 天前
前端面试题---GET跟POST的区别(Ajax)
前端·ajax·okhttp
Komorebi_99992 天前
Axios 是一个基于 Promise 的 HTTP 客户端,可用于浏览器和 Node.js 环境。以下是它的一些主要作用
javascript·ajax
MrsBaek3 天前
前端笔记-AJAX
前端·笔记·ajax