duanju9104 2014-10-28 01:58
浏览 494
已采纳

通过Javascript location.reload传递变量(true)

I have a webpage with a really large MySQL query as the result. The query is changed depending on the user, so it will be different for each person. I am trying to provide a method of resorting the query by making the headers into clickable links.

My query results page is written in PHP and HTML for the most part.

For each column header, I have the following:

echo "<th id='frame_data_table'>
    <a href='javascript:location.reload(true)'>XBox 360 Command</a>
</th>";

On clicking the column header link, the page will reload using the javascript in the a href. This is the most successful way I've been able to get my webpage to reload with all of the query information.

All I need to do now is figure out how to pass another variable upon clicking the header link. I have tried to do syntactical variations of something like

echo "<th id='frame_data_table'>
    <a href='javascript:location.reload(true)+?var1=command_column'>XBox 360 Command</a>
</th>";

with no success. Once I get the variable to pass, I will just grab it with $_GET[''], no problem.

Any advice? It's worth noting that after extensive googling, I saw a lot of location.href. This does not reload my page, and in fact all it really does (in Chrome, anyway) is load a page with just the text url of the page I want.

Is there any way to pass a variable in the url using javascript's location.reload()? Thanks in advance.

-Anthony

UPDATE: Solution

I asked a similar question and was able to obtain a solution. See the link here. The solution is fully explained in the bottom of the question.

  • 写回答

1条回答 默认 最新

  • dowjgrm6787 2014-10-28 02:02
    关注

    Using

    location.href = location.href + "?var1=command_column"
    

    will redirect you to the current URL with the added parameter, i.e. the page will be effectively reloaded.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?