Send multiple values in an input to PHP using jQuery AJAX

3

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.

Ex:

<label>Insira os valores</label>
<ul>
 <li>elemento 1</li>
 <li>elemento 2</li>
 <li>elemento 3</li><span>+ adiciona proximo</span>
</ul>
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

3

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>
</ul>

And then the code

var elementos = '';
$('#lista>li').each(function()
           {
              elementos += $(this).html() +"<br/>";                                                             
           });
$('#lista').append(elementos);

Look here

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

    
01.11.2014 / 01:16