以下是我将如何做我认为你解释。你的问题不是很清楚。
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