redirect user to current page with some querystrin

2020-02-26 15:06发布

When a person clicks on a link, I want to do this:

  1. grab the text from a textbox
  2. encode the text
  3. redirect to currentpage.aspx?search=textboxvalue

I have this so far but its not working:

window.location.href = "?search=" + escape( $("#someId").val());

10条回答
▲ chillily
2楼-- · 2020-02-26 15:27
    function Redirect()
      {
    window.location.href = "URL_TO_BE_Redircted";
      }

then In button (asp.net)

    <asp:Button runat="server" id="btnRedirect" onClientClick="Redirect();return false;"/>

So after clicking on the button the control will go at serverside , and there
you can access the Querystring you form !

查看更多
Emotional °昔
3楼-- · 2020-02-26 15:29

You are changing the wrong location property if you only want to change the search string. I think you want to do this:

location.search = "?search=" + encodeURIComponent( $("#someId").val());
查看更多
一纸荒年 Trace。
4楼-- · 2020-02-26 15:30

you need to prepend the actual base url

window.location.href = window.location.href + "?search=" + escape( $("#someId").val());
查看更多
该账号已被封号
5楼-- · 2020-02-26 15:31

What part isn't working?

Try encodeURI() rather than escape().

查看更多
\"骚年 ilove
6楼-- · 2020-02-26 15:31
$("a").click(function() {

 document.location.href += "?search=" + encodeURIComponent($("#myTextBox").val());


});
查看更多
Fickle 薄情
7楼-- · 2020-02-26 15:32

window.location.href = window.location.href + "?search=" + escape( $("#someId").val()); ?

查看更多
登录 后发表回答