Is there a way to properly pass the inv
array in ajax? Although I can see the inv
array value in console.log, it seems like I am unable to retrieve the array on my php page.
<script>
var FilterCat=['Location','Name','City','Country','State'];
var inv =[];
for(var j = 0; j < FilterCat.length; j++)
{
var a = FilterCat[j];
a =[];
var apply = document.getElementsByName("Filter['"+FilterCat[j]+"'][]");
for(var i = 0; i < apply.length; i++) {
if(apply[i].checked)
{
var F = a.push(apply[i].value);
}
}
inv[FilterCat[j]]=a;
}
$.ajax({
type : "POST",
url : "../module/ApplyFilter.php",
data :{data:inv},
dataType :'JSON',
success:function(response)
{
alert(response);
console.log(response);
}
});
<script>
Even though after the loop each array variable holds values, the data returned by ajax appears as an empty array.
In this code snippet, values are set category wise in respective arrays which need to be passed into a main array in ajax.
The Console response is formatted as follows:
City: Array(0)
length: 0
__proto__: Array(0)
Country: Array(0)
length: 0
__proto__: Array(0)
State: Array(0)
length: 0
__proto__: Array(0)
Location: Array(2)
0: "Distributore"
1: "Vendor"
length: 2
__proto__: Array(0)
Name: Array(0)
length: 0
__proto__: Array(0)
length: 0
__proto__: Array(0)