3

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.

5
  • stackoverflow.com/a/14101120/4248328 Commented 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 . Commented Jul 19, 2017 at 10:56
  • But the above link doesn't show how to pass an array as GET parameter. @AlivetoDie Commented Jul 19, 2017 at 10:56
  • you can't pass array as a parameter. you can pass query-string Commented Jul 19, 2017 at 10:58
  • Okay @AlivetoDie Commented Jul 19, 2017 at 11:38

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

2 Comments

Does my job.@Peter
@UtkarshGarg it's not an array parameter passing.it's called query-string
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.