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 天前
ajax局部更新
前端·ajax·okhttp
一壶浊酒..2 天前
什么是AJAX
前端·javascript·ajax
一枚前端小能手2 天前
🔧 jQuery那些经典方法,还值得学吗?优势与式微的真相一次讲透
前端·javascript·jquery
enki08154 天前
【CANN训练营】+开源之星+GitCode算子开发环境快速搭建手册
javascript·ecmascript·jquery
加洛斯4 天前
AJAX 知识篇(2):Axios的核心配置
前端·javascript·ajax
洛克大航海4 天前
Ajax基本使用
java·javascript·ajax·okhttp
星秀日5 天前
JavaWeb--Ajax
前端·javascript·ajax
小小星尘s5 天前
Python编程实战从基础到高级的完整指南
ajax
我是大头鸟8 天前
XMLHttpRequest 异步请求servlet 上传文件并且带有参数
ajax·servlet
梦65010 天前
JQ 的 AJAX 请求方法
前端·ajax