$.ajax({
type:"get",
url:"add/sql_customer.php",
data: "?title="+title+
"&customerid="+cid+
"&action=savecontract",
success:function(data){
}
});
I want to post titles as an array.. How can I do that?? I get always undefined or an empty variable.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="title" name="title[]" placeholder="Titel-1"/>
<input type="text" id="title" name="title[]" placeholder="Titel-2"/>
<input type="text" id="title" name="title[]" placeholder="Titel-3"/>
</div>
You get the entered titles through an iteration over the input elements with class title-container
:
$('#btn-submit').click(function(){
var titles = [];
$('.title-container').each(function(){
titles.push($(this).val());
});
console.log(titles);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="title-container" placeholder="Title 1"/>
<input type="text" class="title-container" placeholder="Title 2"/>
<input type="text" class="title-container" placeholder="Title 3"/>
<button id="btn-submit">Get titles</button>
</div>