How to add data via $.ajax ( serialize() + extra data ) like this

前端 未结 3 1209
星月不相逢
星月不相逢 2020-11-29 18:36

I want to add extra data after i use $(\'#myForm\').serialize() + extra data

$.ajax({
   type: \'POST\',
   url: $(\'#myForm\').attr(\'action\'),
   data: $(         


        
3条回答
  •  自闭症患者
    2020-11-29 18:46

    Personally, I'd append the element to the form instead of hacking the serialized data, e.g.

    moredata = 'your custom data here';
    
    // do what you like with the input
    $input = $('').val(morevalue);
    
    // append to the form
    $('#myForm').append($input);
    
    // then..
    data: $('#myForm').serialize()
    

    That way, you don't have to worry about ? or &

提交回复
热议问题