Tag: webmethod

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

我正在学习webmethods并使用JSON发回给他们,我在下面有以下内容,但它说它无法找到webmethod(404)。 不知道我哪里出错了,谢谢。 在页面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 […]

Web方法无法删除对象{d:“”}

我想要做的不是发送Object { d : “{“FileID”:”1213″}” }发送”{“FileID”:”1213″}” 我目前的代码: using System; using System.Web.Mvc; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Web; using System.Web.Services; using System.Web.Script.Services; using System.Web.Script.Serialization; [ScriptService] partial class testing_class : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Session[“FileID”] = Request.QueryString[“FileID”]; } public static string returnJSON(object o) { JavaScriptSerializer js = new JavaScriptSerializer(); return […]

使用$ .ajax调用Web方法时,身份validation失败错误

当我进行JQuery调用时,我收到一个身份validation失败的响应: { Message: “Authentication failed.”, StackTrace: null, ExceptionType: “System.InvalidOperationException” } jQuery调用: $(document).ready(function () { //Handle the change event for the drop down list $(“#ddRegions”).change(function () { //create the ajax request $.ajax({ type: “POST”, //HTTP method url: ”, //page/method name data: “{}”, //json to represent argument contentType: “application/json; charset=utf-8”, dataType: “json”, success: function (msg) { //handle […]

不同浏览器中的LinkBut​​ton PageMethod行为不一致

我在一个执行回发的页面上有一个LinkBut​​ton,但也有一个onClientClick事件。 我们的想法是在客户端数据的后台设置一些会话变量(不要问)。 我在Web方法中设置了一个断点来逐步执行代码,我们遇到的是取决于浏览器,PageMethods可能会返回成功消息,失败消息或根本没有消息 。 此外,无论PageMethods结果如何,都可以调用或不调用Web方法。 这是一个方便的结果小图表: Browser PageMethods WebMethod ————– ————- ——————– IE 8, 9, 10 Success Called successfully Safari 5.1.7 Failure *Never called* Firefox 25.0.1 *Neither* Called successfully Chrome v31 Failure Called successfully 这是四种不同的浏览器,以及四种不同的结果。 我已经尝试在服务器端和客户端代码中生成具有相同效果的链接按钮,甚至没有在WebMethod中设置会话变量,结果相同。 可以使用以下简单代码重现代码: function doStuff() { var a = ‘a’; var b = ‘b’; PageMethods.doStuffWebMethod(a, b, doStuffSuccess, doStuffFail); } function doStuffSuccess() […]

我们可以在ASP.NET中为pagemethod和webmethod使用相同的数据表吗?

我正在尝试创建一个新的网页,我需要显示近10个不同的网格视图和图表。 Gridview在pageload事件中绑定,并且通过调用WebMethod使用jquery-ajax方法(使用amcharts以及highcharts)显示图表。 最初我实现页面的方式是在执行gridview(用于显示网格视图数据)和webmethods(用于绘制图表)的同一组存储过程之后。为此页面执行两次相同的sps(一个用于网格,另一个用于图表) )。执行获取数据需要10个sps。 因此,为了提高页面性能,我创建了这样的静态数据表 static DataTable Report1; 并且像这样捆绑了gridview。 private void gvbindReport1() { try { Report1 = new DataTable();//refreshed datatable DataSet ReportDS1 = objmvbl.GetReportGraph(ClientID, date_From, date_To); if (ReportDS1.Tables.Count > 0) { Report1 = ReportDS1.Tables[0];//bindinding data to static datatable } GdReport.DataSource = Report1; GdReport.DataBind(); } catch (Exception ex) { Log.Errlog(“Error Occured in gvbindReport1 : ” + […]

如何从Web服务返回多个值?

我对Web服务世界很陌生,所以请耐心等待。 我正在使用.asmx文件在Visual Studio 2010中创建一个非常简单的Web服务。 这是我正在使用的代码: namespace MyWebService { [WebService(Namespace = “http://www.somedomain.com/webservices”)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] public class Service1 : System.Web.Services.WebService { [WebMethod] public string simpleMethod(String str) { return “Hello ” + str; } } } 当我调用它并为str参数输入值“John Smith”时,它返回: Hello John Smith 我的问题是,为Web服务方法返回超过1个值的最佳做法是什么? 如果值都是相同的数据类型,我应该使用数组吗? 如果值包含不同的数据类型,我需要创建自定义类吗?

如何将的json输出映射到d3.js条形图

嗨,我是d3.js.的新手。我在.aspx文件中有以下[WebMethod]: [WebMethod] public static List GetProductsLINQ() { List lstProducts = new List(); DataTable dtProducts = new DataTable(); string sqlQuery = “SELECT Product_Name, Purchase_Price FROM tblProductMaster”; string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings[“BTrax”].ConnectionString; SqlConnection conn = new SqlConnection(connectionString); SqlDataAdapter da = new SqlDataAdapter(sqlQuery, conn); da.Fill(dtProducts); var productslinq = (from products in dtProducts.AsEnumerable() select new { //Product_Id = products.Field(“Product_Id”), Product_Name […]