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)})
相关推荐
梁辰兴17 小时前
企业培训笔记:axios 发送 ajax 请求
前端·笔记·ajax·vue·axios·node
消失的旧时光-19431 天前
OkHttp SSE 完整总结(最终版)
android·okhttp·okhttp sse
凌辰揽月2 天前
AJAX 学习
java·前端·javascript·学习·ajax·okhttp
生产队队长2 天前
Tomcat问题:启动脚本startup.bat中文乱码问题解决
java·ajax·tomcat
万能小锦鲤3 天前
《Java Web程序设计》实验报告四 Java Script前端应用和表单验证
eclipse·jquery·java web·表单验证·实验报告·java script·java web程序设计
AA-代码批发V哥3 天前
Axios之核心语法详解
ajax
嘉琪0013 天前
2025 js——面试题(7)——ajax相关
开发语言·javascript·ajax
AA-代码批发V哥4 天前
Ajax之核心语法详解
ajax
小李飞飞砖4 天前
OkHttp 的拦截器有哪些
okhttp
PythonicCC5 天前
Django核心知识点详解:JSON、AJAX、Cookie、Session与用户认证
ajax·django·json