I want to send multiple attributes of HTML element generated by php while loop by Ajax call.
For example:
<div id="chart" >
$i=1;
while($i<10){
<input type="text" calss="item" id="$i" >
$i++;
}
</div>
Above code represent the part of the information which I want to send through ajax code as below. The input ids differ from pages representing different item. My question is how to select those ids to get val() inside input & declare them as variables at the same time so that i can pass these values through AJAX call. `
var main = function() {
$('.btn').click(function(){
var item1=$('#1').val();
var item2=$('#2').val();
var item3=$('#3').val();
var item4=$('#4').val();
var item5=$('#5').val();
var item6=$('#6').val();
var item7=$('#7').val();
var item8=$('#8').val();
var item9=$('#9').val();
$.ajax({
type:"POST",
url: "something.php",
cache:0,
data:({
"item1":item1,
"item2":item2,
"item3":item3,
"item4":item4,
"item5":item5,
"item6":item6,
"item7":item7,
"item8":item8,
"item9":item9,
}),
success:function(result){
$('#chart').html(result);
},
complete:function(){
alert('good!!');
}
});
});
}
$(document).ready(main);`