简体   繁体   English

使用Ajax GET将对象值传递给控制器

[英]Pass object value to controller using Ajax GET

 $.ajax({
        url: "/Course/GetChapters/",
        type: "GET",
        data:{id:2},
        beforeSend: function () { },
        success: function (result) {}
    })
    .done(function () {});

Can i pass a complex object via data? 我可以通过数据传递复杂的对象吗?

JQuery Ajax - Documentation JQuery Ajax - 文档

Data -> Data to be sent to the server. 数据 - >要发送到服务器的数据。 It is converted to a query string, if not already a string. 如果不是字符串,它将转换为查询字符串。 It's appended to the url for GET-requests. 它附加到GET请求的URL。 See processData option to prevent this automatic processing. 请参阅processData选项以防止此自动处理。 Object must be Key/Value pairs. 对象必须是键/值对。 If value is an Array, jQuery serializes multiple values with same key based on the value of the traditional setting (described below). 如果value是一个数组,jQuery会根据传统设置的值使用相同的键序列化多个值(如下所述)。

So as long as you have simple name/value pairs it should work. 因此,只要你有简单的名称/值对,它应该工作。 Of course the length of the URL is limited to 2,083 characters. 当然,URL的长度限制为2,083个字符。

try this: var data = 'param1=' + value+ '&param2=' + value; 试试这个:var data ='param1 ='+ value +'&param2 ='+ value; OR var data = '{param1:'val1',param2:'val2',}'. OR var data ='{param1:'val1',param2:'val2',}'。

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

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