简体   繁体   中英

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

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. See processData option to prevent this automatic processing. 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).

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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