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)})
相关推荐
麒麟而非淇淋10 小时前
AJAX 入门 day1
前端·javascript·ajax
陶甜也21 小时前
前后端分离,使用MOCK进行数据模拟开发,让前端攻城师独立于后端进行开发
前端·okhttp
Python私教2 天前
JavaScript 基于生成器的异步编程方案相关代码分享
android·javascript·okhttp
麒麟而非淇淋2 天前
AJAX 进阶 day4
前端·javascript·ajax
+码农快讯+2 天前
JavaScript 基础 - 第17天_AJAX综合案例
开发语言·javascript·ajax
+码农快讯+2 天前
JavaScript 基础 - 第16天_AJAX入门
javascript·ajax·okhttp
空欢ོ喜ꦿ℘゜3 天前
制作论坛帖子页面
前端·javascript·html·jquery
不修×蝙蝠4 天前
后端入门 (JQuery基础) 01
笔记·后端·servlet·html·jquery
doc_wei4 天前
Java智慧云智能教育平台
java·spring·毕业设计·maven·intellij-idea·jquery·课程设计
小刘|4 天前
Ajax 使用流程详解
前端·javascript·ajax