2012-09-14 5 views
0

코드 비하인드가있는 페이지 (default.aspx)가 있습니다. a $ .ajax URL은 한 곳에서 응답을 받고 있는데, 성공한 경우 codebehind 함수를 호출하려고합니다.

(코드를 난독 화하는 동안 실수 한 경우 $ .ajax가 완벽하게 작동하고 원하는 응답이 표시됨).

어떻게 가능합니까? 내가 사용

코드 :

jQuery.support.cors = true; // force cross-site scripting (as of jQuery 1.5) 
    $.ajax({ 
       type: "POST", 
       url: URL, 
       data: parameters, 
       contentType: "application/json; charset=utf-8", 
       dataType: "json", 
       success: function (response) { 

        var resultCount = response.d 
        alert("*** RESULT ****" + resultFields);; 
        var string = StringReturn(); // the codebehind 
        alert(string); 
       }, 
       error: function (e) { 
        alert("Unavailable"); 
       } 
      }); 

Codebehind가 :

 [WebMethod] 
protected static string StringReturn() 
{ 
    return "StringReturn() success"; 
} 

그러나, 나는 StringReturn가 유효한 기능 아니라고 말하는 오류 메시지를 받고 있어요.

도움이 필요하십니까?

: 나는 또한 성공 이벤트에 자바 스크립트 함수를 호출하는 코드, 함수의 존재를 변경 한

<asp:ScriptManager ID="ScriptMgr" runat="server" EnablePageMethods="true"> </asp:ScriptManager> 

: 조언 나는 페이지에 코드의 다음 줄을 추가 한

function HelloWorlds() { 

     alert("HelloWorld() method"); 
     message = PageMethods.StringReturn(); 
     message.toString(); 
     alert(message); 
    } 

그러나 작동하지 않는 것 같습니다. 내가 뭘 놓치고 있니?

+0

내가 [내 Github에서 사이트] 여러 작업 예제 (이 https://github.com/jupaol처럼 호출 할 수 있습니다 /SO-Answers/blob/master/Visual%20Studio%202012/src/SO/WebForms/WebForms_1/Topics/MicrosoftAJAX/PageMethods_ScriptManager.aspx) – Jupaol

+0

코드를 탐색하여 downvoter가 이것을 downvoting하는 이유를 설명해 주시겠습니까? 그냥 curous. – user1666620

답변

1

당신은 당신의 페이지에 scripmanager이 필요하고이 PageMethods.StringReturn()

+0

고마워요, 그게 작동하는지 확인합니다. – user1666620

+0

나는 그것을 얻을 수 없어, 내 OP를 업데이 트했습니다. – user1666620

+0

어떤 오류가 나타 납니까? – MichaelT

관련 문제