500内部错误在jQuery Web方法调用 - IIS 5.1(: - /是啊,我知道...)

500内部错误在jQuery Web方法调用 - IIS 5.1(: - /是啊,我知道...)

问题描述:

我找不到我失踪,有没有IIS设置需要改变,可能?500内部错误在jQuery Web方法调用 - IIS 5.1(: - /是啊,我知道...)

$(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错误。 请帮我解决这个问题。

你需要这条线data: "{'id' : '" + id + "'}",改变data: "{'helpItem' : '" + id + "'}",

为的WebMethod正在helpItem作为参数名称。

所以AJAX功能终于西港岛线是

$.ajax({ 
      type: "POST", 
      url: "AjaxWebMethods.aspx/GetHelpText", 
      contentType: "application/json; charset=utf-8", 
      data: "{'helpItem' : '" + id + "'}", 
      dataType: "json", 
      success: AjaxSuccess, 
      error: AjaxError 
     }); 

,让你的服务器端方法静态这样

[System.Web.Services.WebMethod()] 
    public static string GetHelpText(string helpItem) 
    { 

检查文章帮助你为这个:Calling Server Side function from Client Side Script

+0

谢谢!更新,但仍然得到相同的东西:( – 2013-03-13 14:11:29

+0

@MadamZuZu - 检查更新.. – 2013-03-13 14:15:38

你的数据是id和您的Web方法期待helpItem。尝试对齐两者。

data: "{helpItem: '" + id + "'}"

另一件事是尝试添加static到您的WebMethod声明。

[System.Web.Services.WebMethod()] 
public static string GetHelpText(int helpItem) 
{ 
+0

谢谢!这是你和Pranay的回应的组合!它现在工作:) – 2013-03-13 14:16:00