JQuery how to submit only changed fields when the form has some data array

后端 未结 3 1558

I have a database structure with an one to many relationship. In the html form, there are similar inputs with a name \'item[]\' or \'file[]\' to make the data to be an array

3条回答
  •  执笔经年
    2021-01-14 23:03

    var data = {};
    $(function(){
        $(document).on('change', 'input', function(){
        data[this.name] = this.value;
      });
    });
    

    You can add a change event to the inputs and add the changed values to the data object or append fields to form data. So data object with contain only the changed values.

    You can use formdata for sending files data. Please refer the this link.

    How to use FormData for ajax file upload

提交回复
热议问题