I want to pass an array as url GET parameter and redirect to new page. I don't know how to pass an array with window.location.href
. Is there any way in Ajax to redirect to new page with array as parameter(with or without window.location.href
) or is there any other function for redirecting to other page in which I can pass an array as parameter from the front-end.
Asked
Active
Viewed 1.2k times
3

Utkarsh Garg
- 125
- 1
- 2
- 12
-
https://stackoverflow.com/a/14101120/4248328 – Alive to die - Anant Jul 19 '17 at 10:53
-
You can store your aaray to localstorage and then when you land on the page where you want to redirect, you can read that localStorage . – Himanshu Upadhyay Jul 19 '17 at 10:56
-
But the above link doesn't show how to pass an array as GET parameter. @AlivetoDie – Utkarsh Garg Jul 19 '17 at 10:56
-
you can't pass array as a parameter. you can pass query-string – Alive to die - Anant Jul 19 '17 at 10:58
-
Okay @AlivetoDie – Utkarsh Garg Jul 19 '17 at 11:38
2 Answers
7
with jQuery $.param function you can convert array to http query
var data = {myArr: [1,2,3,4,5]};
console.log("index.php?" + $.param(data));
// index.php?myArr%5B%5D=1&myArr%5B%5D=2&myArr%5B%5D=3&myArr%5B%5D=4&myArr%5B%5D=5

Peter
- 16,453
- 8
- 51
- 77
-
-
@UtkarshGarg it's not an array parameter passing.it's called query-string – Alive to die - Anant Jul 19 '17 at 11:12
2
Try this
info[0] = 'hi';
info[1] = 'hello';
info = JSON.stringify(info);
$.ajax({
url: "index.php?info="+info,
data: data_to_send,
success: function(msg){
$('.answer').html(msg);
}
});
In backend code just json_decode the info and use.

K.B
- 885
- 5
- 10