如何使用 jQuery 和 Ajax 仅返回一个字符串以及如何将其插入到 jdialog 中的 DDL 中?

发布于 2024-09-26 00:35:39 字数 1675 浏览 0 评论 0 原文

我正在尝试创建一个动态模块,将一个对象放在屏幕上。然后将打开一个 jQuery 对话框,其中包含三个下拉列表。当我在第一个下拉列表中选择一个值时,我尝试通过 Ajax 过滤下一个列表中的结果。

这是我的 JS 代码:

$("#ddlTableType").live(
        'change',
        function() 
        { 
            var GetTablesCodes = $.ajax({
                url:'AjaxActions/TableCodes.aspx?ObjectType=' + $("#ddlTableType").val(),
                async:false                 
            }).responseText; 
          //alert(GetTablesCodes);
          //alert(GetTablesCodes.$('#hidCodesList').val());
          //alert($('#hidCodesList').val());
        }
   );

在 ASP.NET 页面中,我正在执行以下操作:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TableCodes.aspx.cs" Inherits="AjaxActions_TableCodes" %>

<form id="form1" runat="server">
     <asp:HiddenField ID="hidCodesList" runat="server" />
</form>

此页面背后的代码:

public partial class AjaxActions_TableCodes : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
    DataSet dsCodesList = DbHelper.ExecuteDataSet(
                        ConfigurationManager.AppSettings["ConnStr"],
                        "spObjectCodesByTYpe_Select",
                        new SqlParameter("@ObjectType", Request.QueryString["ObjectType"])
                );

    hidCodesList.Value = "";
    for(Int16 CodeListIndex=0;CodeListIndex<dsCodesList.Tables[0].Rows.Count;CodeListIndex++)
    {
        hidCodesList.Value += dsCodesList.Tables[0].Rows[CodeListIndex]["Value"].ToString() + ",";
    }
}

}

在第一次调用警报时,我获得了整个页面。我可以看到隐藏字段填充了我需要的数据。我怎样才能提取这些数据?最后,所有下拉列表都在 JDialog 中,因此这可能会导致问题。

I'm trying to create a dynamic module where I drop an object on screen. Then a jQuery dialog opens with three drop-down lists. When I select a value in the first drop-down list I'm trying to filter the results in the next list via Ajax.

This is my JS code:

$("#ddlTableType").live(
        'change',
        function() 
        { 
            var GetTablesCodes = $.ajax({
                url:'AjaxActions/TableCodes.aspx?ObjectType=' + $("#ddlTableType").val(),
                async:false                 
            }).responseText; 
          //alert(GetTablesCodes);
          //alert(GetTablesCodes.$('#hidCodesList').val());
          //alert($('#hidCodesList').val());
        }
   );

In the ASP.NET page I'm doing the following:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TableCodes.aspx.cs" Inherits="AjaxActions_TableCodes" %>

<form id="form1" runat="server">
     <asp:HiddenField ID="hidCodesList" runat="server" />
</form>

The code behind for this page:

public partial class AjaxActions_TableCodes : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
    DataSet dsCodesList = DbHelper.ExecuteDataSet(
                        ConfigurationManager.AppSettings["ConnStr"],
                        "spObjectCodesByTYpe_Select",
                        new SqlParameter("@ObjectType", Request.QueryString["ObjectType"])
                );

    hidCodesList.Value = "";
    for(Int16 CodeListIndex=0;CodeListIndex<dsCodesList.Tables[0].Rows.Count;CodeListIndex++)
    {
        hidCodesList.Value += dsCodesList.Tables[0].Rows[CodeListIndex]["Value"].ToString() + ",";
    }
}

}

In my first call to alert I get the entire page. In that I can see the hidden field filled with the data I need. How can i extract this data? Finally, all the drop-down lists are in a JDialog so maybe that is causing an issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月依秋水 2024-10-03 00:35:39

关于 ASP.NET jQuery 和级联下拉列表的一般答案

从我可以从您的问题中看出,您尝试创建的用户体验是一个模式弹出窗口(通过 jDialog),其中包含一系列< em>级联下拉列表。有很多方法可以使用这个范例。使用搜索词“级联下拉列表asp.net”将为您提供大量关于如何将各种解决方案付诸实践的示例。

这里有几篇文章可能会有所帮助

更具体地解决您的问题

本质上,您希望通过 jDialog 加载一个模式弹出窗口,其中包含三个下拉列表。您应该绑定到第一个下拉列表的 onchange 事件。绑定函数应使用 jQuery 调用 Web 方法,该方法返回数据以填充下一个下拉列表。

[编辑]
上面链接的文章(使用 jQuery 和 JSON 在 ASP.Net 中构建级联 DropDownList )显示了如何通过 JSON 和 jQuery 对象的追加方法将选项附加到下拉列表的示例。我已经提取了相关的附加代码。

$("#ddlCities").append($("<option></option>").val(this['ID']).html(this['City']));

[/编辑]

General Answer on ASP.NET jQuery and Cascading Drop-down lists

From what I can discern from your question the user experience you are trying to create is a modal popup (via jDialog) which contains a series of cascading drop-down lists. There are quite a few ways to put this paradigm into use. Using the search terms "cascading drop-down lists asp.net" will net you a lot of examples on how to put the various solutions into practice.

Here are a couple of articles which may help

More Specific to your problem

Essentially you want to load a modal popup via jDialog which contains three drop-down lists. You should bind to the onchange event of the first drop-downs. The bound function should use jQuery to call a web method which returns the data to fill the next drop-down.

[edit]
The article linked above (Building Cascading DropDownList in ASP.Net Using jQuery and JSON) shows an example of how to append options to a drop-down list via JSON and the append method of a jQuery object. I've pulled out the pertinent append code.

$("#ddlCities").append($("<option></option>").val(this['ID']).html(this['City']));

[/edit]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文