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.
-
stackoverflow.com/a/14101120/4248328Death-is-the-real-truth– Death-is-the-real-truth2017-07-19 10:53:49 +00:00Commented Jul 19, 2017 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– Himanshu Upadhyay2017-07-19 10:56:51 +00:00Commented Jul 19, 2017 at 10:56
-
But the above link doesn't show how to pass an array as GET parameter. @AlivetoDieUtkarsh Garg– Utkarsh Garg2017-07-19 10:56:55 +00:00Commented Jul 19, 2017 at 10:56
-
you can't pass array as a parameter. you can pass query-stringDeath-is-the-real-truth– Death-is-the-real-truth2017-07-19 10:58:25 +00:00Commented Jul 19, 2017 at 10:58
-
Okay @AlivetoDieUtkarsh Garg– Utkarsh Garg2017-07-19 11:38:22 +00:00Commented Jul 19, 2017 at 11:38
Add a comment
|
2 Answers
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
2 Comments
Utkarsh Garg
Does my job.@Peter
Death-is-the-real-truth
@UtkarshGarg it's not an array parameter passing.it's called query-string