AJAX 数据传输 页面跳转

axiosHelper


let res = await this.api.post(
 	'/api/projects/select', 
 	{ id: this.id}
);


let _this = this;
_this.axiosHelper
.post(url, this.id ? project : this.ruleForm)
.then((response) => {
    // this.hideLoading();
    if (response.status == 200) {
        console.log(response);
        if (response.data.code !== 0) {
            _this.$message.error({
                message: response.data.msg,
            });
            return;
        }
        _this.$message.success({
            message: '保存成功',
        });
        _this.isAddProject = false;
        _this.$emit('closeDialog');
        _this.$emit('updateChildProject');
        _this.resetForm();
    } else {
        _this.$message({
            message: '提交失败',
            type: 'error',
        });
    }
})
.catch((err) => {
    // this.hideLoading();
    _this.$message({
        message: '提交失败,' + err.response.data.message,
        type: 'error',
    });
});

通用

function submit(val) {
   var dataObj = {};
   dataObj.departGuid = $("#departGuid").val();
   dataObj.states = 0;
   $.ajax({
      url: ctx + "beforehand/wholeDepartment/submit",
      type: "post",
      data: JSON.stringify(dataObj),
      dataType: "json",
      contentType: 'application/json',
      success: function (result) {
	  $.modal.alertSuccess('提交审核成功,下一步' + nextStatesName);
      error: function () {
          $.modal.alertWarning("操作失败");
      }
   });
}
@PostMapping("/evaluationSubmit")
@ResponseBody
public AjaxResult evaluationSubmit(@RequestBody WholeDepartment wholeDepartment) {
   return wholeDepartmentService.evaluationSubmit(wholeDepartment);
}

传输方式一,只有一个参数get (@PathVariable)

  1. JS
updateUrl: prefix + "/edit/{id}",

ctx + "beforehand/evaluationInfo/export1/" + id
  1. 控制器
@GetMapping("/edit/{evaluationTargetCompletionGuid}")
 public String edit(@PathVariable("evaluationTargetCompletionGuid") String evaluationTargetCompletionGuid, ModelMap mmap)

传输方式二,多个参数get (@RequestParam)

访问路径

http://localhost:8071/direct?msg=%27%E5%95%8A%E5%95%8A%E5%95%8A%27&code=6

控制器

@GetMapping("/direct")
public String sendEmail(@RequestParam Map<String,Object> params){
    String msg = params.get("msg").toString();
    rabbitTemplate.convertAndSend("EmailExchange","EmailRoutingKey",msg);
    return "OK";
}

传输方式三,只有一个参数 post

  1. JS
function fileDown(path){
	 $.ajax({
	 	 url: ctx + "beforehand/projectFile/fileDown?filePath="+path,
           	 type: "post",
           	 success: function (result) {
                	 alert('控制器成功');
         	 },
         	 error: function () {
                	alert("控制器错误");
            	}
          });
}
  1. 控制器
public String Down( String filePath) {

传输方式四 Post dataObj

  1. JS
function fileDown(path){
        dataObj = {};
        dataObj.filePath = path;
        $.ajax({
            url: ctx + "beforehand/projectFile/fileDown",
            type: "post",
            data: JSON.stringify(dataObj),
            dataType: "json",
            contentType: 'application/json',
            success: function (result) {
                alert('控制器成功');
                 },
            error: function () {
                alert("控制器错误");
            }
        });
 }
  1. 控制器
public String Down( @RequestBody ProjectFile projectFile ) {

@RequestParam和@RequestBody的区别

由于spring的RequestParam注解接收的参数是来自于requestHeader中,即请求头,也就是在url中,格式为xxx?username=123&password=456,而RequestBody注解接收的参数则是来自于requestBody中,即请求体中。

传数组

后端用数组类型接收

前端:http://localhost:8591/api/promotion/push/pickcenter/1,3

@PostMapping("/pickcenter/{useType}")
public ResponseEntity<Map> pickcardcenter(@PathVariable("useType") int[] useTypeArray){
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

飘然生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值