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)})
相关推荐
不考研当牛马3 天前
jQuery 核心速查与实战笔记
jquery
来恩10034 天前
jQuery对Ajax的支持
前端·ajax·jquery
来恩10035 天前
jQuery事件处理方法
前端·javascript·jquery
流年如夢5 天前
类和对象(中)
开发语言·javascript·ajax·ecmascript
你觉得脆皮鸡好吃吗6 天前
XSS渗透 COOKIE
网络·http·okhttp·网络安全学习
努力成为AK大王6 天前
从前端到数据库:一个 Web 项目的完整通信链路解析
前端·数据库·ajax·jdbc
来恩10039 天前
jQuery选择器
前端·javascript·jquery
彭于晏Yan9 天前
OkHttp 与 RestTemplate 技术选型对比
java·spring boot·后端·okhttp
JohnnyDeng949 天前
OkHttp 拦截器链与缓存策略:深度解析网络层的核心机制
okhttp·缓存
胖胖胖胖胖虎10 天前
okhttp Stream Load 含认证请求重定向
starrocks·okhttp