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)})
相关推荐
传人once2 天前
选择文件按钮样式如何美化
前端·html·css3·jquery·html5
墨天梦3 天前
B15_HTTP解析与OkHttp拦截器
网络协议·http·okhttp
传人once5 天前
网页文字滚动效果如何做
前端·css·html·jquery·html5
传人once6 天前
多图片上传预览功能如何写
前端·css·html·jquery·html5
传人8 天前
网页文字滚动效果如何做
前端·javascript·jquery
研☆香11 天前
jQuery + Swiper.js 实现动态渲染轮播图
前端·javascript·jquery
liangshanbo121512 天前
面试题:页面需要发起大量 Ajax / HTTP 请求时,如何优化请求性能?
前端·http·ajax
RobinDevNotes12 天前
JAX 分布式训练,和 PyTorch 有什么不一样
人工智能·深度学习·ajax
小七在进步12 天前
类和对象(四)
java·javascript·ajax
没差c21 天前
RetrofitClient写接口、导包、配置、路径
java·spring boot·okhttp