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)})
相关推荐
wno70417 小时前
node.js中使用jquery
前端·node.js·jquery
程序员大阳2 天前
副队长JavaScript教程(67)-Ajax初识:背景、历史与核心概念
javascript·ajax·同步·异步·概念·背景·来是
程序员大阳2 天前
副队长JavaScript教程(70)-Ajax同源策略与跨域
javascript·ajax·同源策略·跨越·corp
星_离9 天前
《Ajax - 实战基础篇》
前端·ajax
李纲明9 天前
WordPress 结账页一直转圈不跳支付:AJAX、缓存排除、支付回调和 REST 怎么逐层核
运维·ajax·缓存·wordpress·woocommerce·devdiy·结账
鶴哥只手遮天9 天前
jQuery 4.0 源码架构与工程实践-第 01 章 · 全景与工程结构:一个 20 岁库的自省
前端·javascript·jquery
鶴哥只手遮天10 天前
jQuery 4.0 源码架构与工程实践-第 10 章 尺寸、几何与显隐
前端·javascript·jquery
变与不变80611 天前
jQuery细节以及使用应用场景
前端·javascript·jquery
爱吃火鸡面呀13 天前
Spark RDD 行动算子(Action)详解
windows·ajax·spark
MandalaO_O14 天前
SpringMVC 响应返回值类型笔记
okhttp