I am in a problem. I have a page with several text field with same class name and different attribute values. I would like to create an array which having unique key with joining the text field attribute values. And pass it to a PHP page using ajax.
My problem is
I can create the array successfully. But when I try to send the data through ajax, it become empty and the post array did not contain that value. But when I try to console the array, then it has the value
My JQuery code is
$(document).on('click', '#mybutton', function () {
var c_array = [];
$('.class').each(function(){
var val1 = $(this).attr('attr1');
var val2 = $(this).attr('attr2');
var val3 = $(this).attr('attr3');
var key = val1+'_'+val2+'_'+val3;
var no = $(this).val();
c_array[key] = no;
alert(c_array[key]);
});
console.log(c_array);
var type = 'check_cookie';
$.ajax({
type: 'POST',
url: 'action.php',
dataType: 'json',
async: false,
data: { type: type, c_array: c_array },
success: function (data) {
console.log(data);
if (data.msg !== '' && data.msg !== null) {
window.location = 'new.php';
}
else {
alert('error');
}
}
});
});
What is the problem with this code? Please help me. Thank u all in advance....