发送POST请求到Controller操作在IE中而不是在Chrome中工作

时间:2017-05-23 05:40:10

标签: ajax asp.net-mvc asp.net-core

行动代码是:

//tickets is null in chrome but has value in IE
public async Task<IActionResult> ChangeStatus(string tickets)
{
   //Code goes here
}

ajax call

var selectTickets = '"ticket1","ticket2"'    
$.ajax
     ({
          type: 'post',
          url: "/SkyBusTickets/ChangeStatus/",
          data: {'tickets': selectTickets},
          success: unexpiredTicketsBulkStatusChangeSuccess,
          failure: unexpiredTicketsBulkStatusChangeError
     });

在Chrome中,它在控制台中出现错误

  

jquery.js:9536 POST http://localhost:54656/SkyBusTickets/ChangeStatus/   500(内部服务器错误)

需要做些什么才能使它在两种浏览器中都有效?

修改

如果我将操作方法​​更改为以下操作方法,它也将停止在IE中工作

   //tickets is null in both chrome & IE
    public async Task<IActionResult> ChangeStatus([FromBody]string tickets)
    {
       //Code goes here
    }

1 个答案:

答案 0 :(得分:0)

检查一下,它对我有用

//ajax side 
$(document).ready(function () {
        var selectTickets = '"ticket1","ticket2"'
        $.ajax
             ({
                type: 'post',
                url: "api/Test/ChangeStatus",
                dataType: 'json',
                data: { "": selectTickets },
                success: function () {

                },
                failure: function () {

                }
             });
    });

在控制器部分

[HttpPost]
public string ChangeStatus([FromBody]string tickets)
{
    return "sdfdf";
}

您可以参考此链接 http://www.c-sharpcorner.com/UploadFile/dacca2/web-api-with-ajax-understand-formbody-and-formuri-attribute/