繁体   English   中英

从 js 文件将数组传递给 controller 中的方法并取回值

[英]Passing an array to a method in controller from a js file and getting back the value

我正在尝试将值从 js 传递到 Home controller 中的方法网关,我想要返回结果(整数)

$.ajax({
            url: '/Home/gateway?s=' + dates[],
            type: 'POST',
            dataType: 'json',
            data: { id: 'value' },
            success: function (data) {
                alert("success");
            },
            error: function () {
                alert('error');
            }
        });

您在 POST 请求中传递 url 查询参数,按照设计,该请求应该期望有效负载主体。 为什么不在数据 object 中添加另一个名为 dates 的属性并将其值设置为dates数组?

$.ajax({
  url: '/Home/gateway',
  type: 'POST',
  dataType: 'json',
  data: {
    id: 'value',
    dates
  },
  success: () => {
    alert("success");
  },
  error: () => {
    alert('error');
  }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM