2013-03-13 5 views
3

제가 누락 된 부분을 알아낼 수 없으므로 IIS 설정을 변경해야합니까? 다음과 같이500 내부 오류 jQuery 웹 메서드 호출 - IIS 5.1 (: -/yea i know ...)

$(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) 오류가 계속. 제발 이해해주세요. 의 WebMethod은 매개 변수의 이름으로 helpItem 복용으로

답변

4

당신은 data: "{'helpItem' : '" + id + "'}",

이 줄 data: "{'id' : '" + id + "'}",을 변경해야합니다.

그래서 아약스 기능은 마지막으로

$.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

감사합니다. 업데이트되었지만 여전히 동일한 것을 얻고 있습니다. ( –

+0

@ MadamZuZu - 업데이트를 확인하십시오 .. –

3

귀하의 데이터 id이며, 귀하의 웹 방식은 helpItem입니다. 두 가지를 정렬하십시오. 시도

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

또 다른 것은 당신의 WebMethod 선언에 static를 추가하는 것입니다.

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

감사합니다! 그것은 당신과 Pranay의 응답의 조합이었습니다! 지금 작동 중입니다 :) –