JSON回发到c# webmethod添加文字控制

2024-03-28

我正在学习 webmethods 并使用 JSON 发回给它们,我在下面得到了以下内容,但它说找不到 webmethod (404)。不知道我哪里出错了,谢谢。

在页面 JavaScript 中:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
       <script type="text/javascript">
           $(document).ready(function () {
               $(".FilterResults").click(function () {
                   var topic = $(".DropDownList1").val();
                   var number = $(".DropDownList2").val();
                   var month = $(".DropDownList3").val();
                   $.ajax({
                       type: "POST",
                       url: "filterresultshold.asmx/filterresults",
                       data: "{'args': '" + topic + "'}",
                       contentType: "application/json; charset=utf-8",
                       dataType: "json",
                       success: function (msg) {
                           // If you return something from the method, it can be accessed via msg.d                
                       }
                   });

                   // To prevent the postback
                   return false;
               });
           });
</script> 

在ascx中:

<form id="form1" runat="server">
 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
    <div>
        <asp:PlaceHolder ID="PlaceHolder1" runat="server"><asp:Literal ID="Literal1" Text="Text to display" mode="PassThrough" runat="server" /></asp:PlaceHolder>
        <asp:DropDownList ID="DropDownList1" class="DropDownList1" runat="server"></asp:DropDownList>
        <asp:DropDownList ID="DropDownList2" class="DropDownList2" runat="server"></asp:DropDownList>
        <asp:DropDownList ID="DropDownList3" class="DropDownList3" runat="server"></asp:DropDownList>
        <asp:Button ID="FilterResults" class="FilterResults" runat="server" Text="Fill DropDownList" />
    </div>
</form>

后面的代码中:

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

/// <summary>
/// Summary description for filterresults
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class filterresultshold : System.Web.Services.WebService {

    [System.Web.Services.WebMethod]
    public void filterresults(string args)
    {
        string[] data = args.Trim().Split(',');
        string topic = data[0];
        string number = data[1];
        string month = data[2];
        string control = "<umbraco:Macro alias='pdfarchivelist' runat='server' topic='" + topic + "' number='" + number + "' month='" + month + "'></umbraco:Macro>";
        //LiteralControl literal = new LiteralControl(control);
        //PlaceHolder PlaceHolder1 = new PlaceHolder();
        //PlaceHolder1.Controls.Add(literal);
    }

}

然后在.ascx后面的代码中:

public partial class usercontrols_pdfarea : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {      
        if (!Page.IsPostBack)
        {
            // Populate Drops
            var rootNode = uQuery.GetRootNode();
            DropDownList1.Items.Add(new ListItem("SELEZIONA NUMERO"));
            DropDownList2.Items.Add(new ListItem("SELEZIONA MESE"));
            DropDownList3.Items.Add(new ListItem("SELEZIONA ARGOMENTO"));

            //display the password on the Gallery Folder in the media area
            var startMedia = uQuery.GetMediaByName("pdfs").FirstOrDefault();
            var DropList = rootNode.GetDescendantNodes().Where(x => x.NodeTypeAlias == "File");

            foreach (var item in startMedia.Children)
            {
                DropDownList1.Items.Add(new ListItem(item.getProperty("number").Value.ToString())); //NUMBER
                DropDownList2.Items.Add(new ListItem(item.getProperty("month").Value.ToString())); //MONTH
            }

            foreach (var item in startMedia.Children.Select(p => p.GetPropertyAsString("topic")).Distinct().ToList())
            {
                DropDownList3.Items.Add(new ListItem(item.ToString()));
            }
        }
    }
}

// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class filterresultshold : System.Web.Services.WebService {

只需按照评论中的建议进行即可

顺便说一句,filterresults不应该是静态的

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JSON回发到c# webmethod添加文字控制 的相关文章

随机推荐

  • 从 kdb 中的字符串中提取数字

    我对 kdb q 很陌生 我遇到过从字符串中提取数字的问题 有什么建议么 Example AZXER 1234 MARKET should output 1234 Assume that there is only one number i
  • JOIN 语法中缺少关键字

    在提出问题之前我已经搜索过该网站 但没有遇到相关的内容 我确信这是一个荒谬的基本错误 我只从 0 计算机背景学习 Oracle SQL 大约 4 个月 我计划在本月底学习 1z0 051 所以复习一下所有章节 在这个子句中 我试图获取工资高
  • 要嵌入 .NET 应用程序的 XPS 或 XAML 查看器?

    是否有查看器对象或 ActiveX 控件可用于在我的 NET 应用程序中嵌入 XPS 文档或 XAML GUI 您可以使用元素主机控制 http msdn microsoft com en us library system windows
  • 使用express模块​​时找不到模块“cookie”

    我需要你的帮助来使用express构建rest API 我已经尝试了很多版本的express 也有 CookieParser 中间件 但我刚刚收到上述错误 Error Cannot find module cookie at Functio
  • 无法在本地或远程找到“开发”或“主”分支。 - 语义gitversion

    我在 azure 中有一个存储库 它有默认分支 main 另外 我在 yml 文件中有一项用于语义版本控制的任务 task gittools gitversion gitversion task GitVersion 5 displayNa
  • TypeError:注册不是在React中使用React Hook Form的函数

    The Error Message If i dont use the Inputs inside div then it works perfectly but when i use Input inside div it shows m
  • Spring SseEmitter 导致响应提交后无法转发异常

    给定一个简单的控制器 其方法如下 RequestMapping method RequestMethod GET value id update public ResponseEntity
  • 如何使用 karma 在测试文件之间共享模拟?

    我正在一个有角度的应用程序中工作 其中许多测试文件共享相同的模拟 我想知道如何提取这些模拟并将它们放入单独的文件中 我尝试创建一个对象并在测试中重用它 但出现异常 ReferenceError 找不到变量 需要 业力文件 module ex
  • 使用 jQuery 检查 div 是否隐藏

    这是我的div div style display none div 然后我有一个显示按钮 当您单击时将显示 div show click function car2 show 所以现在我想检查 div 是否 car2在表单提交之前仍然隐藏
  • 如何使用键盘快捷键转到 VS Code 中的下一个错误(不是下一个问题)?

    In VS Code the F8 keyboard shortcut takes you to the next problem Problems can be errors warnings or info I want to cycl
  • 每组平均值以及组中变量的数量[重复]

    这个问题在这里已经有答案了 我想生成一个表 其中包含每个范围的组 每个组中变量的平均值和计数 我有一个如下所示的 data frame Variable Shap 1 0 10 6 0 50 7 0 30 5 0 40 9 0 10 9 0
  • 在后台停止音频

    有一个名为 IHeartRadio 的应用程序 可让您设置睡眠计时器 该计时器将在指定的时间间隔后关闭音频 您首先选择要收听的电台 然后选择睡眠时间 之后广播电台将停止播放 应用程序不需要位于前台即可发生这种情况 应用程序如何在后台停止音频
  • 在 Gatsby 上运行 SASS 不起作用

    昨天 我能够设置 gatsby 的入门包实例并部署到 github 页面 从那时起 我在本地更新了我的react js 文件 这似乎在本地运行良好 现在我想编译我的 sass 我找不到有效的解决方案 这是我尝试安装的 sass 编译器 sa
  • Python 定时脚本

    如何让 python 脚本每天在设定的时间运行 确切地说是下午 2 00每天 有没有办法让它每天运行两次 不太确定从哪里开始 谢谢您的帮助 不要重新发明和使用任何系统上已有数十年的功能 cron 除此之外 PyPI 列出了一堆与 cron
  • 如何使用 imaplib 创建电子邮件并将其发送到特定邮箱

    我正在尝试使用 python 的 imaplib 创建一封电子邮件并将其发送到具有特定名称的邮箱 例如收件箱 任何人都有一些很好的建议 IMAP 协议不是为发送电子邮件而设计的 它旨在操纵邮箱 要创建电子邮件并发送它 您可以使用 SMTP
  • 以编程方式绘制气泡

    I would like to have a bubble with a precentage value in my app I can t use 9 patches as i want it to be customizable an
  • 数据集排序

    In DataTable我可以排序 dataTable DefaultView Sort SortField DESC 我得到了一个DataSet从数据库中 我想知道我可以对DataSet就像我做的那样DataTable 您仍然可以从数据集
  • 如何集成测试两个 Rails 应用程序

    我们有两个独立的 Ruby on Rails 应用程序 一个接受上传的文件 另一个根据另一个应用程序收到的上传生成文件 我们正在尝试整合端到端黑盒回归和集成测试 以证明当您将某个文件上传到第一个应用程序时 您可以指望从另一个应用程序中获取某
  • 为什么音频可视化直播无法在移动设备/Safari 上运行?

    我正在尝试基于 Three js 示例制作音频直播可视化工具 https trijs org examples q visua webaudio visualizer https threejs org examples q visua w
  • JSON回发到c# webmethod添加文字控制

    我正在学习 webmethods 并使用 JSON 发回给它们 我在下面得到了以下内容 但它说找不到 webmethod 404 不知道我哪里出错了 谢谢 在页面 JavaScript 中