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)})
相关推荐
qwert10371 天前
跨域问题解释及前后端解决方案(SpringBoot)
spring boot·后端·okhttp
符哥20083 天前
基于 OkHttp+Retrofit 实现 JSON / 表单 / XML/Protobuf 数据格式全解析
okhttp·json·retrofit
Cg136269159744 天前
js引入方式
前端·javascript·ajax
Pu_Nine_94 天前
企业级 Axios 配置实战:从基础到完整封装
前端·ajax·axios·网络请求·企业级
XiaoLeisj4 天前
Android 网络编程入门到实战:HttpURLConnection、JSON 处理、OkHttp 与 Retrofit2
android·网络·okhttp·json·gson·retrofit2·jsonobjecy
凯鑫BOSS5 天前
Pbootcms查看详细报错信息
okhttp
徐先生 @_@|||1 个月前
Spark的DataFrame的Map Task和Reduce Task深入理解
ajax·spark·php
跟着珅聪学java1 个月前
以下是使用 jQuery 获取元素 CSS 类名的详细教程,涵盖基础方法、实际应用及注意事项:
前端·css·jquery
韩曙亮1 个月前
【jQuery】jQuery 选择器 ⑤ ( jQuery 排他思想 | 核心概念 | 核心逻辑拆解 )
前端·javascript·jquery·jquery筛选方法·排他思想·筛选方法·jquery排他思想
爱敲代码的小鱼1 个月前
AJAX(异步交互的技术来实现从服务端中获取数据):
前端·javascript·ajax