我在c# asp.net中有一个and方法和一个jquery代码来调用该方法。如果我像我的服务webService .asmx一样在.asmx页面中放置代码,它可以正常工作。我是从同一个母版上来的。但是当我从.aspx页面调用它时,它根本不起作用。我调用此webservice按钮单击事件。在这两种情况下都会触发按钮单击,我在javascript中通过警报进行了检查。
调用webmethod的母版页代码如下:
<%-- WebService Data--%>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type ="text/javascript" >
$(document).ready(function () {
$("#btni").click(function () {
var dataSent = "{roll:" + 1 + ",name:\"" + "Mubashir\"}"
$.ajax({
type: "Post",
url: "EmailList.aspx/heelo",
data: dataSent,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var studentInfo = response.d;
alert(JSON.stringify(response.d));
$("#output").empty();
$.each(studentInfo, function (index, Info) {
//alert(index);
//alert(index.Info);
$("#output").append(
'<strong>Roll : </strong>' + Info.roll + ' ' +
'<strong>Name : </strong>' + Info.name + ' ' +
'<strong>Address : </strong>' + Info.address + '<br/> '
);
});
},
failure: function (msg) {
alert(msg.d);
$("#output").text(msg);
}
});
});
});
</script>
<%-- WebService数据--%>
EmailList.aspx.cs页面上的webmethod如下所示:
[WebMethod]
public string heelo(int roll, string name)
{
return "Mubashir";
}
//WebService
如果我将相同的方法放在myservice.asmx代码文件上,那么它可以正常工作。
发布于 2015-01-08 10:04:23
使您的方法static
[WebMethod]
public static string heelo(int roll, string name)
{
return "Mubashir";
}
要想更多地了解为什么ASP.Net AJAX PageMethods必须是static
,请阅读这。
https://stackoverflow.com/questions/27837355
复制相似问题