简体   繁体   中英

post json + form data in single ajax call

I have a json and form data to send in an ajax post call, how can I combine both:

something like

data : $("#my-form").serialize() + $({ pkeys: ckeys, page: cpage }).serialize()

$.ajax({
    type: "POST",
    url: base_url + "pkey/action/edit",
    data: $("#my-form").serialize() + {
        pkeys: ckeys,
        page: cpage
    } //get this right
}).done(function (data) {
    alert("success");

});

$.param exactly meets your requirement.

$("#my-form").serialize() + '&' +
$.param({
    pkeys: ckeys,
    page: cpage
})

see further example through jquery docs .

Adding +'&pkeys='+ckeys+'&page='+cpage; instead of $({ pkeys: ckeys, page: cpage }).serialize() works.

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