0

I am trying to load the url of a search page by specifying both the path I want to load and the search parameters that should be appended.

For example I'm loading /foo/?q=1&a=2 I would try to type something in javascript like this:

location.href = /foo/?q=1&a=2

Then when that's run I get an invalid token exception at the '&' character. I'm well versed in javascript and jquery so I'm open to an answer in either language.

I just need to be able to set location.href and it's associated search parameter so that I can load the page correctly. OR if you have suggestions as to other ways to do this I'm open to those as well.

Regards

cvocvo
  • 1,586
  • 2
  • 23
  • 38

1 Answers1

3

You need your string in quotes like this:

location.href = "/foo/?q=1&a=2";

Javascript was probably interpreting /foo/ as a regular expression and then trying to make sense of the other characters after it as options on the regex.

jfriend00
  • 683,504
  • 96
  • 985
  • 979