简体   繁体   中英

Redirect page with location.href

I am trying to redirect one url using JavaScript for passing values to Java code using

location.href = "/something/uId=" + Idvalue + "time=" + "timeValue"

Here I am checking from two radio buttons that are today and Week radio buttons.

It is working fine for week and passing id and time value ie, 200 (example), week (Example).

But when it comes to today option it is passing only time value only. I tried the following ways

location.href += "&uId=" + uId;
// and 
location.href += "time=" + today + "&uId=" + uId; 

But it is passing only today only. I was surprised to see additional variables timeframe=today&x=26&y=4 but I did't pass these x and y values.

It's hard to understand exactly what has gone wrong here. If uId is not being passed, I think that it is a different area of the code (whatever is responsible for setting uId that has broken.

The way you are forming URLs seems to be incorrect. The queryString of a URL should look like this:

url.com?firstArgName=firstArgValue&secondArgName=secondArgValue& ....

So your initial line should look like this:

location.href="/something?uId="+Idvalue+"&time="+timeValue

If your webserver is working in a standard way.

I believe that x and y variables comes because you have image button.

About your redirect page, try as follows:

location.href = '/something?uId='+ Idvalue +'&time='+ TimeValue;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM