将查询字符串传递给Ajax加载的Jquery模态对话框



我看到了如何做到这一点的例子,但我遇到的一切都是针对.net或PHP页面的。我正试图用一个经典的ASP页面来做这件事,而且我是JQuery的新手,所以我正试图弄清楚如何去做

我有一个链接,可以打开JQuery模式对话框。模式对话框的"打开"功能从一个单独的.asp页面引入其内容。我希望由querystring元素加载的内容。

我已经对它进行了测试,并通过输入静态查询字符串使其工作。但我不知道如何将一个动态值传递给字符串,或者如何传递多个值(意味着其中包含"&"的查询字符串)。

这是我正在使用的代码:

<script type="text/javascript">
$(function () {
$("#example2").dialog({
            autoOpen: false,
            width: 650,
            modal: true,
            open: function() {
            //here's where I need to dynamically pass multiple elements
            $("#example2").load("test.asp?id=28&value=30");}
        });
        $("#showdialog2")
            .click(function () {
                $("#example2").dialog("open");
                return false;
        });
});

触发它的链接和对话框div:

<a href="" id="showdialog2">Show the Dialog</a>
<div id="example2" title="My First Ajax Dialog2"></div>

由于这是一个经典的ASP页面,有没有办法将querystring元素从"显示对话框"链接传递到对话框打开调用?

谢谢你的帮助!

我想你想这样做:

<a href="/some/link/for/progressive/enhancement.asp?id=<%= id %>" id="showdialog2" data-id="<%= id %>">Show the Dialog</a>
<div id="example2" title="My First Ajax Dialog2"></div>

要添加更多变量,请使用更多自定义属性,并修改以下内容以包含额外的属性。

$(function () {
    $("#example2").dialog({
        autoOpen: false,
        width: 650,
        modal: true,
        open: function() {
    });
    $("#showdialog2")
        .click(function () {
            $("#example2").dialog("open");
            $("#example2").load("test.asp?id=" + $(this).attr('data-id') + "&value=30");}
            return false;
    });
});

另一种选择是使用$(this).href()并手动解析该值以提取查询字符串(您可能会正则化它),但使用自定义属性是一种更简单的方法。

您可能可以链接openload调用,如果您不打算在关闭时销毁对话框,那么最好为对话框设置默认内容。如果你想要这些例子,请告诉我。


链接(注意preventDefault而不是返回false):

$("#showdialog2").click(function (event) {
    $("#example2").html('<div style="text-align: center"><img src="/assets/images/ajax-loader.gif" /></div>')
        .dialog("open")
        .load("test.asp?id=" + $(this).attr('data-id') + "&value=30");
    event.preventDefault();
});

这将在单击时重置对话框,使其只有一个ajax微调器(在此处获取您的微调器),这样您就可以在不重新加载的情况下重复使用。

如果您正在尝试使用当前的querystring集合,您可以执行类似于以下的操作

<% 
Sub outputQueryString()
    dim key
    for each key in Request.Querystring
        Response.Write key & "=" & Request.Querystring(key) & "&"
    next
End Sub
%>

$("#example2").load("test.asp?<% outputQueryString() %>");}

最新更新