Reputation: 1072
My problem is
jQuery.ajax({
type: "POST",
url: "../ajax/si-notificar_investigacion.php",
data: {
idincidente: $("#idincidente").val(),
arrControlls : arrControlls
},
dataType: 'json',
async: false,
success: function(datos) {
alert(datos);
}
});
this is my ajax
Now I use arrControlls
variable as array which is comes from another function
now if arrControlls
is like
[0] = "test1";
[1] = "test1";
[2] = "test1";
then it is okey I get this variable as an array in action page
BUT if I use value like this
['sid_1'] = "test1";
['sid_2'] = "test1";
['sid_3'] = "test1";
then I do not get variable in action page WHY?
adding this lines for more detail
I am using jquery function for getting data
function getAllControllValue()
{
var arrControlls = new Array();
$("#container-div input").each(function(){
arrControlls[$(this).attr('id')] = $(this).val();
});
return arrControlls;
}
Upvotes: 0
Views: 397
Reputation: 944301
Arrays are expected to have sequential, numeric indexes. That is what they are for. You can give them named properties, but tools designed to do something with the data in the array tend to ignore them.
Given an array anywhere in data
, jQuery will only pay attention to the numeric indexes.
If you want to have named keys, then use a plain object.
Initialise arrControlls
with {}
not new Array()
.
Upvotes: 2
Reputation: 743
User JSON.stringify like this:
JSON.stringify(arrControlls)
jQuery.ajax({
type: "POST",
url: "../ajax/si-notificar_investigacion.php",
data: {
idincidente: $("#idincidente").val(),
arrControlls : JSON.stringify(arrControlls)
},
dataType: 'json',
async: false,
success: function(datos) {
alert(datos);
}
});
Upvotes: -1