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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -