C#   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了c# – jQuery Web方法调用的500内部错误 – IIS 5.1(: – /我知道……)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我无法弄清楚我错过了什么,是否有可能需要更改的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个弹出窗口
错误
然后501错误.
请帮我解决这个问题.

解决方法

您需要更改此行数据:“{‘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

大佬总结

以上是大佬教程为你收集整理的c# – jQuery Web方法调用的500内部错误 – IIS 5.1(: – /我知道……)全部内容,希望文章能够帮你解决c# – jQuery Web方法调用的500内部错误 – IIS 5.1(: – /我知道……)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。