javascript - Submitting array of textfields using FormData() through ajax -


i have array of input text

<input type="text" name="highlight" value="1"/> <input type="text" name="highlight" value="2"/> 

i used ajax , formdata() submit server.

var form = $(this); var formdata = new formdata(form[0]); var target = form.attr('action');  $.ajax({       url: target,       type: 'post',       data: formdata,       processdata: false,       contenttype: false,     })     .done(function(data){         console.log(data.message);     }); 

**expected server result:**highlight=['1','2']
**actual server result:**highlight=2
im using nodejs server

you need add brackets input name attributes highlight[]. way browser knows part of same array , won't overwrite 1 other.

<input type="text" name="highlight[]" value="1"/> <input type="text" name="highlight[]" value="2"/> 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -