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)})
相关推荐
YHHLAI8 小时前
Ajax — 异步数据交互
ajax·okhttp·交互
meilindehuzi_a10 小时前
深入理解 Ajax 异步请求:从 XMLHttpRequest 到 Node.js HTTP 服务实践
http·ajax·node.js
研☆香11 小时前
jQuery特殊属性操作方法
前端·javascript·jquery
拾年2751 天前
从零手写 Ajax:用原生 XHR 搭建前后端交互全流程
前端·javascript·ajax
slongzhang_1 天前
jquery 修复怪异模式html未声明“<!DOCTYPE html>”
前端·html·jquery
研☆香3 天前
jQuery补充知识点
前端·javascript·jquery
এ慕ོ冬℘゜6 天前
【双月日期范围选择器】博客(可直接交作业 / 上线)
前端·javascript·交互·jquery
Xaire9 天前
行行查案例-数据解密-国密s4-webpack打包模块补齐
okhttp
霸道流氓气质9 天前
Spring AI Ollama 连接超时问题排查与解决:OkHttp 读超时配置全指南
人工智能·spring·okhttp
零壹AI实验室12 天前
NVIDIA RTX Spark深度测评:个人AI智能体时代真的来了?
人工智能·ajax·spark