【问题标题】:Redirect to another page using javascript without query string使用没有查询字符串的javascript重定向到另一个页面
【发布时间】:2013-07-05 08:46:46
【问题描述】:

我想重定向到另一个页面并仅使用 javascript 传递一些参数。我不应该使用查询字符串。有什么办法可以做到这一点?我正在研究 asp.net。

我希望此重定向与 devexpress 调度程序控件一起使用,当用户单击约会时,通过将所选约会的 ID 作为参数传递,用户将被重定向到另一个页面。它不应作为查询字符串传递。

我也想知道如何从重定向页面中检索这种不可见的参数。

好的,我找到了我的解决方案。

我使用 javascript 单击设置为 style="display:none"<asp:Button>。在我的场景中,我可以获得我单击的调度程序约会的属性。然后,我将这些属性放在隐藏字段中,并在此“不可见”按钮的服务器端单击事件中,使用这些隐藏字段值通过服务器端进行重定向。我的代码如下

<asp:Button ID="Appointment" runat="server" Text="sample" 
    onclick="Appointment_Click" style="display:none"/>
<asp:HiddenField ID="hfID" runat="server" />
<asp:HiddenField ID="hfSubject" runat="server" />
<asp:HiddenField ID="hfDate" runat="server" />

<script type="text/javascript" language="javascript">
    function OnAppointmentClick(s, e) {
        //debugger;
        var apt = scheduler.GetAppointmentById(e.appointmentId);

        var apt1 = scheduler.GetAppointmentProperties(e.appointmentId);

        var aptID = document.getElementById('<%= hfID.ClientID %>');
        var aptDate = document.getElementById('<%= hfDate.ClientID %>');
        var aptSubject = document.getElementById('<%= hfSubject.ClientID %>');
        aptID.value = e.appointmentId;
        var date = (apt.startDate.getMonth()+1) + '/' + apt.startDate.getDate() + '/' + apt.startDate.getYear(); 
        aptDate.value = date;
        aptSubject.value = apt.CODE;
        document.getElementById('<%= Appointment.ClientID %>').click();
    }    
    </script>

【问题讨论】:

  • 这是你的作业吗? :)
  • 没有。这是我的办公室工作。我正在使用 devexpress 调度程序。

标签: c# asp.net c#-4.0 url-redirection


【解决方案1】:

试试这个 document.location.href = "window-location.html"

已经问过here

【讨论】:

  • 对不起,您提供的链接没有讨论传递参数。
【解决方案2】:

试试这个:

ASP.net 代码:

Response.Headers.Add("id", "testtest");
Response.Redirect("http://www.somesite.com/somepage.aspx");

Java 脚本代码:

window.location = 'http://www.somesite.com/somepage.aspx?q=manvswild';

jQuery 代码:

var url = "http://www.somesite.com/somepage.aspx?q=manvswild";
$(location).attr('href',url);

jQuery Ajax 代码:

$.ajax({
    type : 'POST',
    url : 'page.aspx',
    data : {
        paramname1 : "put_param_value_here",
        paramname2 : "put_param_value_here",
        paramname3 : "put_param_value_here"
    },
    dataType : 'html',
    success : function (e) {
        window.location = e;
    }
});

//或短方法是

$.post("page.aspx", {
    param1 : 'one',
    param2 : 'two'
}, function (data) {
    window.location = data;
});

jQuery 插件: http://plugins.jquery.com/project/query-object

alert($.query.set("section", 5).set("action", "do").toString());

输出:

?section=5&action=do

【讨论】:

  • 您的回答很好,但出于安全原因,我不允许使用查询字符串。
  • @Nisha:然后尝试使用 aspx 中的会话进行操作。使用会话来传递参数,或者您可以对您的安全数据使用加密/解密。祝你好运!!
猜你喜欢
  • 1970-01-01
  • 2018-10-25
  • 2014-12-03
  • 1970-01-01
  • 1970-01-01
  • 2018-08-21
  • 1970-01-01
  • 1970-01-01
  • 2015-08-05
相关资源
最近更新 更多