2012-03-29 4 views
1

현재 자바 스크립트에서 aspx.cs의 메소드를 호출하려고합니다.자바 스크립트에서 aspx.cs 메소드를 호출합니다.

자바 스크립트 : 아래

내가 현재 가지고있는 것입니다

function loadPins(passValue) { 
    callServer2("myMethod", passValue); 
} 

function callServer2(requestMethod, clientRequest) { 
var pageMethod = "Default.aspx/" + requestMethod; 

$.ajax({ 
    type: 'POST', 
    data: clientRequest, 
    dataType: 'JSON', 
    contentType: 'application/json', 
    url: pageMethod , //Method to call 
    success: function (result, status) { 
     alert("success"); 
    }, 
    error: function (xhr, status, error) { 
     alert("ERROR"); 
    } 
    }); 
} 

aspx.cs : 나는 그것을 호출하고 CallServer2를 입력하지만 결코 칠 것 같다 참조 디버깅

[WebMethod] 
public static string myMethod(string passedVal) 
{ 
    value = passedVal; 
    return "true"; 
} 

내 중단 점 내 aspx. 내 성공 또는 오류 메시지 알림도 표시되지 않습니다.

제안 사항? 내가 현재 무엇입니까

오류 :

error - <html> 
     <head> 
     <title> Unknow we method myMethod.<br>Parameter name: 
    methodName</title> 
    <style> 
     body{font-family:verdana";font-weight:normal;font-size: 
     .7em;color:black} 
      p 
    {font-family:"Verdana";font-weightbold;color:black;margin-top: -5px} 
b{font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} 
H1{ 
font-family:"veranda";font-weight:normal;font-size:18pt;colour:red} 
H2{ 
font-family:"Verdana";font-weight:normal ;font-size:14pt color:maroon} 
pre{font-family:"Lucida Console";font-size .9em} 
.marker{font-weight:bold;color:black;text-decoration:none;} 
.version{color:gray;} 
.error{margin-bottom:10px} 
.expandable{text-decoration:underline, font-weight:bold; color:navy; cursor:hand;} 
</style> 
<head> 

<code> 
An unhanded exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code> 
... 

* 참고 나는 당신의 페이지에 있어야 그것이 말하는 모든

+0

코드를 다시 확인하지 않으면 서버 기능을 통해 디버그를 수행 할 수 있습니까? –

+0

또한 업데이트 $ .ajax 함수를 표시 할 수 있습니까? –

답변

0
$.ajax({ type: "POST", 
     url: pageMethod, contentType: "application/json; charset=utf-8", 
     data: "{passedVal:" + JSON.stringify(clientRequest) + "}", dataType: "json", 
     success: function (result, status) { 
     alert("success"); 
    }, 
    error: function (xhr, status, error) { 
     alert("ERROR"); 
    } 

    }); 

.

+0

할 일이 있습니까? HTML 코드처럼 보였던 정말 오랜 오류가 있습니다 – user1219627

+0

어떤 오류가 발생하고 있습니까? 당신은 또한 방화 광에서 오류를 확인할 수 있습니까? –

+0

메신저 그래서 나는 프로그램을 통해 단계 수있는 Visual Studio를 사용하여. 내 질문에 오류가 게시됩니다 너무 오래 당신과 함께 괜찮 으면 – user1219627

0
  1. ScriptManager 위의 줄 끝에서 정말 ... 그게 전부 넣어 didnt한다 .
  2. ScriptManager.EnablePageMethods을 true로 설정해야합니다.

또한이처럼이 줄을 변경해보십시오 : 당신이 데이터 passedVal로 데이터를 전달해야하고 변수를 캐릭터 라인 화 않습니다

contentType: "application/json; charset=utf-8" 
0

그냥 만들 .. 희망이 도움이 있는지 당신은 당신의 clientRequest에

data: "{'passedVal':'" + your_data+ "'}", 

희망이 당신을 도와이있다!

관련 문제