gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 17:57:32 25 4
gpt4 key购买 nike

我正在学习 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 不应该是静态的

关于c# - JSON 回发到 c# webmethod 添加文字控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13175652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com