Send multiple values in an input to PHP using jQuery AJAX


I have a script that aims to insert multiple items into a list of a form using Ajax.

For each element inserted in this list, a next one should be added.

After inserting X elements, it should take all values and play in just one input, adding to the end of each element as a br/ tag, via PHP send to MySQL.


<label>Insira os valores</label>
 <li>elemento 1</li>
 <li>elemento 2</li>
 <li>elemento 3</li><span>+ adiciona proximo</span>
The submit POST must generate an array (element1 + element2 + element3) by adding br/ to the end of each element, and sent only in input name="elementos"

asked by anonymous 31.10.2014 / 19:57

1 answer


You can have a more or less structure of the type:

<label>Insira os valores</label>
<ul id='lista'>
 <li class='item'>elemento 1</li>
 <li class='item'>elemento 2</li>
 <li class='item'>elemento 3</li> 
 <span>+ adiciona proximo</span>

And then the code

var elementos = '';
              elementos += $(this).html() +"<br/>";                                                             

Look here

And then you use the jQuery function itself for ajax this link .

01.11.2014 / 01:16