2011-08-31 8 views
5

문자열을 포함하는 javascript 변수를 jquery.ajax를 통해 서버에 전달합니다. "성공"조건이 호출되었지만 서버 측 WebMethod는 호출되지 않습니다. 클라이언트 :WebMethod가 호출되지 않습니다.

$.ajax({ 
      type: "post", 
      url: "Playground.aspx/childBind", 
      data: {sendData: ID}, 
      //contentType: "application/json; charset=utf-8", 
      dataType: "text", 
      success: function (result) { alert("successful!" + result.d); } 
     }) 

서버 :

[WebMethod] 
    public static string childBind(string sendData) 
    { 
     return String.Format("Hello"); 
    } 

답변

6

하여 Ajax 요청을 위해 다음과 같은 수정 시도는 :

$.ajax({ 
      type: "post", 
      url: "Playground.aspx/childBind", 
      data: "{sendData: '" + ID + "'}", 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: function (result) { alert("successful!" + result.d); } 
     }) 

주의 dataType와 문자열로 data 값이 변경되었습니다.

0

"ID"(또는 다른 필드) 문자열에 '='와 같은 따옴표가 포함 된 데이터 오류가 표시됩니다. 이 문제를 해결 :

var DTO = {'sendData': ID}; 

       $.ajax({ 
        "type": "POST", 
        "dataType": 'json', 
        "contentType": "application/json; charset=utf-8", 
        "url": sSource, 
        "data": JSON.stringify(DTO), 
        "success": function (msg) { 
         //do something 
        } 
       }); 
0

다음과 같이하십시오 : JQuery와 :

   var dataString = JSON.stringify({ 
        contractName: contractName, 
        contractNumber: contractNumber 
       }); 

       $.ajax({ 
        type: "POST", 
        url: "CreateQuote.aspx/GetCallHistory", 
        data: dataString, 
        contentType: "application/json; charset=utf-8", 
        dataType: "json", 
        success: function (result) { 
         alert(result); 
          OpenLightBox('divDelete'); 

        } 
       }); 

ASPX.CS을 :

 [System.Web.Services.WebMethod] 
     public static string GetCallHistory(string contractName, string contractNumber) 
     { 
      return "Nalan"; 
     } 
관련 문제