2011-01-03 5 views
0

아래의 ASPX 페이지를 실행할 때마다 내부 서버 오류가 발생합니다. 이것은 내가 웹에서 복사 한 것입니다 &이 문제의 원인을 파악하기 위해 원본을 제거했습니다.jquery 문제는 항상 오류를 반환합니다.

ASPX 페이지 :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="x.aspx.cs" Inherits="x" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head id="Head1" runat="server"> 
     <title>Adventure Works</title> 

     <style type="text/css"> 
     .loading 
     { 
      background-image: url('ajax-load.gif'); 
      background-repeat: no-repeat; 
     } 
     </style> 

    <script src="/Scripts/jquery-1.3.2.js" type="text/javascript"></script> 

    <script type="text/javascript"> 

     function CallService() { 

      $('input[type=button]').attr('disabled', true); 
      $("#CustDetails").html(''); 
      $("#CustDetails").addClass("loading"); 
      $.ajax({ 
       type: "POST", 
       url: "GetVendor.asmx/GetVendorDetails", 
       data: "{'ID': " + $("#txt_id").val() + "}", 
       contentType: "application/json; charset=utf-8", 
       dataType: "json", 
       success: OnSuccess, 
       error: OnError 
      }); 

      function OnSuccess(data, status) { 
       alert('success'); 

       $("#CustDetails").removeClass("loading"); 
       // $("#textVendorNameLookup").html(data.d); 
       $('input[type=button]').attr('disabled', false); 
      } 

      function OnError(request, status, error, response) { 

       $("#CustDetails").removeClass("loading"); 
       $("#CustDetails").html(request.statusText); 
       $('input[type=button]').attr('disabled', false); 

       //$("#textVendorNameLookup").html(request.statusText); 
      } 

     } 
    </script> 


</head> 
<body> 
    <form id="DocForm" runat="server"> 
    <div> 

     <table style="width:31%;"> 
      <tr> 
       <td> 
        Enter Contact ID</td> 
       <td> 
        :</td> 
       <td> 
        <input id="txt_id" value="12" type="text" /><input id="btnGo" type="button" 
         value="Get Details" onclick ="CallService(); return false;"/></td> 
      </tr> 
      </table> 
    <br /> 
    <div id="CustDetails" style="width: 60%; height: 75px;"> 
    &nbsp; 
     </div> 
    </div> 
    </form> 
</body> 
</html> 

ASMX 페이지

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Services; 
using System.Data.SqlClient; 
using System.Configuration; 
using System.Data; 

/// <summary> 
/// Summary description for AdvService 
/// </summary> 
[WebService(Namespace = "http://tempuri.org/")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 

[System.Web.Script.Services.ScriptService] 
public class GetVendor : System.Web.Services.WebService { 

    public GetVendor() { 

     //Uncomment the following line if using designed components 
     //InitializeComponent(); 
    } 

    public int GetVendorDetails(int id) 
    { 
     return id; 

    } 
} 

고사 페이지;

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

using Telerik.Web.UI; 
using System.Data; 
using System.Data.Sql; 
using System.Data.SqlClient; 
using System.Configuration; 
using System.Reflection; 


public partial class x : System.Web.UI.Page 
{ 

    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 

} 

AHIA, 래리 ...

+0

을이 시도? – Vadim

+0

asp.net 페이지에서 JSON이 제대로 반환되지 않는다는 것을 알고 있습니까? JSON으로 형식화되지 않은 숫자도 있습니다. 이를 위해 JSON.NET http://json.codeplex.com을 사용하십시오. 그리고'GetVendorDetails'는 WebMethod조차도 아닙니다 !!! – balexandre

+0

@balexandre Json.net은 필요하지 않습니다. 내 예를 잠시 게시하는 것을 보아라. – Tahbaza

답변

1

난 당신이 너무 좋아 [WebMethod]와 그 방법을 장식 할 필요가 있다고 생각 :

[System.Web.Script.Services.ScriptService] 
public class GetVendor : System.Web.Services.WebService { 

    [WebMethod] 
    public int GetVendorDetails(int id) 
    { 
     return id; 

    } 
} 
+0

chprpipr입니다. [WebMethod]를 추가하고 동일한 결과를 얻었습니다. 다른 아이디어? 나는 jQuery의 초보자이므로 @ 빨대를 쥐고 ​​있습니다. – larryr

+0

@larryr : 스크린 샷이나 오류 텍스트를 게시 할 수 있습니까? – chprpipr

+0

실제 오류가 없으며 'Internal Server Error'를 반환합니다. 아래에서 몇 가지 조언을 받았고 Chrome에서 'Inspect Element'를 사용하여 #txt_id가 채워져 있어야하는 데이터 매개 변수가 발견되지 않았습니다. ("Message ":"잘못된 웹 서비스 호출, 매개 변수에 대한 누락 된 값 : – larryr

0

당신은 아약스 호출이 호출 될 때 (있는 경우)를 실행하는 어떤 코드를 볼 수 VS.net의 디버거를 사용할 수 있습니다. 이것은 "내부 서버 오류"아약스 문제로 시작하는 좋은 장소입니다.

다음으로 Firebug (웹 개발을위한 Firefox 플러그인)을 사용하지 않는다면 훨씬 더 많은 Ajax 호출 디버깅을 위해 반드시 확인해야합니다. 귀하의 문의 사항에 좀 더 구체적으로 귀하의 GetVendorDetails 방법을 변경하는 것이 더 도움이 될지 확인하십시오.

using System.Web.Script.Services; 
using System.Web.Services; 
using System.Web.Script.Serialization; 

...

[WebMethod] 
[ScriptMethod(ResponseFormat=ResponseFormat.Json)] 
public string GetVendorDetails(string Id) { 
    // do your processing here to get your result 
    return new JavaScriptSerializer().Serialize(yourObjectInstanceToBeJsonSerialized); 
} 
+0

당신도 ASMX Service가 항상 XML을 출력한다는 것을 알고 있습니까? pure JSON을 반환하려면 랩퍼 호출의 WCF를 사용하십시오. – balexandre

+2

@balexandre, ResponseFormat.Json 데코레이터 참고; 그것은 내 $ .ajax jquery 호출에 Json을 반환합니다. 충분히 말하면 – Tahbaza

1

확인을,이에 대한 대답은 '부팅에이다 머리 '... 데이터 쌍을 지정할 때 이름은 웹 서비스뿐만 아니라 데이터에서도 마찬가지입니다. 모든 도움/제안을 해주신 모든 분들께 감사드립니다. - 당신은 클릭 페이지로드 또는 버튼에 서버 오류가 발생하는 경우

1

, 그것은 작동합니다

function CallService() { 

    var CatID = {"ID": $('#txt_id').val()} 
    $('input[type=button]').attr('disabled', true); 
    $("#CustDetails").html(''); 
    $("#CustDetails").addClass("loading"); 
    $.ajax({ 
     type: "POST", 
     url: "AdvService.asmx/GetCtcDetails", 
     data: JSON.stringify(CatID),, 
     contentType: "application/json; charset=utf-8", 
     dataType: "json",   

     success: OnSuccess, 
     error: OnError 
    }); 

} 
관련 문제