[英]Load the Pagemethods by button click in jQuery
<script type="text/javascript">
$(document).ready(function() {
$('#loadbtn').click(function() { // can 't load
opts = {
title: 'ABCD',
series: [{
neighborThreshold: 0
}],
axes: {
xaxis: {
//smethg
},
yaxis: {
//smethg
}
},
};
PageMethods.LoadAsset(LoadSucc, LoadFail); //Want to load by button click event
function LoadSucc(obj) {
goog = obj;
//Something
alert("Data loaded");
}
function LoadFail() {
alert("Data missing");
}
});
});
</script>
在我的C#代码中
[System.Web.Services.WebMethod]
public static Array LoadAssetAssignView()
{
//something
return something;
}
ASP:
<asp:Button runat="server" ID="loadbtn" Text="Load" />
实际上,该功能开始在文档准备功能中工作。 我想在单击按钮时加载该功能。 我该怎么做呢?
我认为您缺少在html中声明该方法的方法。 例:
<div>
Your Name :
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
<input id="btnGetTime" type="button" value="Show Current Time"
onclick = "ShowCurrentTime()" />
</div>
然后调用jQuery:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
<script type = "text/javascript">
function ShowCurrentTime() {
$.ajax({
type: "POST",
url: "CS.aspx/GetCurrentTime",
data: '{name: "' + $("#<%=txtUserName.ClientID%>")[0].value + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function(response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
alert(response.d);
}
</script>
最后是pagemethod。 您可以通过以下链接进行引用: http : //www.aspsnippets.com/Articles/Call-ASPNet-Page-Method-using-jQuery-AJAX-Example.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.