以下是我將如何做我認爲你解釋。你的問題不是很清楚。
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
$.ajax({
type: "POST",
url: "PageName.aspx/MethodName",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Do something interesting here.
}
});
HTML
<html>
<head>
<title>Calling a page method with jQuery</title>
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="Default.js"></script>
</head>
<body>
<div id="Result">Click here for the time.</div>
</body>
</html>
JS
$(document).ready(function() {
// Add the page method call as an onclick handler for the div.
$("#Result").click(function() {
$.ajax({
type: "POST",
url: "Default.aspx/GetDate",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Replace the div's content with the page method's return.
$("#Result").text(msg.d);
}
});
});
});
但同樣我真的不知道你正在嘗試做的。你真的很含糊。
更簡單的方法是使用'ajax' – Baby
可以請你舉個例子說明如何通過ajax做到這一點?處理方法已經完成。我只需要能夠在HTML上調用它。 – jbdeguzman
聽起來像是會幫助你的東西是AJAX,但很難分辨出理想的解決方案,因爲你目前的情況沒有被詳細描述。例如:爲什麼你不能在請求的頁面中提供所有的信息(爲什麼你需要提出另一個請求)?爲什麼你需要一個隱藏的輸入?你能向我們展示你現有代碼的基本部分,並解釋它爲什麼這樣做嗎? – Barney