I need to pass a muliple values to another page using ajax, so please help to make multidimensional.
I need a array like this.
<script type="text/javascript">
var concertArray = [
["Billy Joel", "99", "equal.png"],
["Bryan Adams", "89", "higher.png"],
["Brian Adams", "25", "lower.png"]
];
</script>
var concertArray = [ ["Billy Joel", "99", "equal.png"], ["Bryan Adams", "89", "higher.png"], ["Brian Adams", "25", "lower.png"] ];
This will work.
You can access values using concertArray[i][j]
Please try below code. Surely it will works.
var items = [
["Billy Joel", "99", "equal.png"],
["Bryan Adams", "89", "higher.png"],
["Brian Adams", "25", "lower.png"]
];
console.log(items[0][0]); // to access 1st array
console.log(items);
You can pass array, but give JSON a thought:
Snippet to show a utility function that may come handy:
var concertArray = [
["Billy Joel", "99", "equal.png"],
["Bryan Adams", "89", "higher.png"],
["Brian Adams", "25", "lower.png"]
];
function arrayToJSON(arr, keys) {
var obj = {};
arr.forEach(function(value, index) {
var tempObj = {};
value.forEach(function(innerValue, innerindex) {
tempObj[keys[innerindex]] = innerValue;
})
obj[index] = tempObj;
});
return obj;
};
console.log(arrayToJSON(concertArray, ['name', 'age', 'avatar']))
</div>
var m;
var click_qty = [];
for(l=1;l<cont;l++)
{
var tst1=document.getElementById('tst1'+m).value;
var tst2=document.getElementById('tst2'+m).value;
n = l -1;
click_qty[n]=[tst1,tst2];
}
$.ajax({
type: 'POST',
url:'ajax_result.php',
data:{ click_qty:JSON.stringify(click_qty), },
success: function(msg1){
//your code
}
for decode this json use like thiS
$new_val = str_replace('],[','!~',$_POST['click_qty']);
$new_val = str_replace('\"',"",$new_val);
$new_val = str_replace('[[',"",$new_val);
$new_val = str_replace(']]',"",$new_val);
$fnl_prod = explode("!~",$new_val);
$fnl_count = count($fnl_prod);
$new_display = "";
$fnd_val = "";
for($i=0;$i<$fnl_count;$i++)
{
$res_prod = explode(',',$fnl_prod[$i]);
$res_prod[0] //------>tst1
$res_prod[1] //------>tst2
}