我目前正在嘗試在javascript的aspx.cs裏調用一個方法。從javascript調用aspx.cs方法
下面是我目前有:
的Javascript:
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
:
[WebMethod]
public static string myMethod(string passedVal)
{
value = passedVal;
return "true";
}
當我調試我看到它調用並輸入CallServer2
,但它似乎永遠不會打我在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>
...
* 注意我沒有把......這就是真正意義上面說上面後
可以通過服務器功能進行調試,如果不再檢查代碼,您的路徑必須是錯誤的。 – 2012-03-29 05:19:23
您還可以顯示更新$ .ajax函數。 – 2012-03-29 05:22:46