c# – jQuery Web方法调用的500内部错误 – IIS 5.1(: – /我知
发布时间:2020-12-16 01:53:37 所属栏目:百科 来源:网络整理
导读:我无法弄清楚我错过了什么,是否有可能需要更改的IIS设置? $(document).ready(function () { function AjaxSuccess(result) { alert('result: ' + result); } function AjaxError(result) { alert("error"); alert(result.status + ' ' + result.statusText)
我无法弄清楚我错过了什么,是否有可能需要更改的IIS设置?
$(document).ready(function () { function AjaxSuccess(result) { alert('result: ' + result); } function AjaxError(result) { alert("error"); alert(result.status + ' ' + result.statusText); } $(".hlp").click(function () { var myVal= $(this).val(); var id = $(this).attr('id'); $.ajax({ type: "POST",url: "AjaxWebMethods.aspx/GetHelpText",contentType: "application/json; charset=utf-8",data: "{'helpText' : '" + id + "'}",dataType: "json",success: AjaxSuccess,error: AjaxError }); }); }); 我的网络方法如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class AjaxWebMethods : System.Web.UI.Page { protected void Page_Load(object sender,EventArgs e){ } #region Exposed WebMethods [System.Web.Services.WebMethod()] public string GetHelpText(string helpItem) { string helpText = "testing web method"; return helpText; } #endregion } 我不断得到2个弹出窗口 解决方法
您需要更改此行数据:“{‘id’:’”id“’}”,数据:“{‘helpItem’:’”id“’}”,
因为webmethod将helpItem作为参数名称. 所以ajax功能最终会成功 $.ajax({ type: "POST",data: "{'helpItem' : '" + id + "'}",error: AjaxError }); 并使您的服务器端方法像这样静态 [System.Web.Services.WebMethod()] public static string GetHelpText(string helpItem) { 检查文章可以帮助您:Calling Server Side function from Client Side Script (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |