How do I send a complex JSON object from an HTML form using SYNCHRONOUS page POST?

后端 未结 4 2108
清歌不尽
清歌不尽 2021-01-15 11:21

My server is using ServiceStack and would like to receive some data like this:

{
    Customer: {
        Company: \"TheCompany\",
        RegionCode: \"AU_NS         


        
4条回答
  •  南方客
    南方客 (楼主)
    2021-01-15 11:46

    Attach a submit handler to the form which places the JSON as the value of a pre-created hidden input field within the form.

    $(form_to_submit).on('submit', function() {
        $(form_to_submit).find(hidden_input).val(json_value);
    });
    

    To submit a form using jQuery you use:

    $(form_to_submit).submit();
    

提交回复
热议问题