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)})
相关推荐
林的快手8 小时前
伪类选择器
android·前端·css·chrome·ajax·html·json
还是鼠鼠8 小时前
详细介绍:封装简易的 Axios 函数获取省份列表
前端·javascript·vscode·ajax·前端框架
清风细雨_林木木17 小时前
wangEditor 编辑器 Vue 2.0 + Nodejs 配置
vue.js·okhttp·编辑器
不会&编程3 天前
第四章 Vue 中的 ajax
前端·vue.js·ajax
Leven1995274 天前
Spark 性能优化 (三):RBO 与 CBO
ajax·性能优化·spark
Dontla4 天前
jQuery介绍(快速、简洁JavaScript库,诞生于2006年,主要目标是简化HTML文档操作、事件处理、动画和Ajax交互)
javascript·html·jquery
WeiLai11125 天前
DeepSeekApi对接流式输出异步聊天功能:基于Spring Boot和OkHttp的SSE应用实现
人工智能·spring boot·后端·okhttp
闲暇部落5 天前
Android网络框架——OKHttp
android·java·okhttp
还是鼠鼠6 天前
使用XMLHttpRequest发送带查询参数的 GET 请求并动态展示数据
前端·javascript·vscode·ajax·bootstrap
网络安全(华哥)6 天前
CSRF攻击&XSS攻击
okhttp·xss·csrf