//[webmethod(enablesession = true)]//或[webmethod(true)]
[WebMethod]
public static string GetUserName()
{
return "234";
}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "POST",
contentType: "application/json",
url: "JqueryDemo.aspx/GetUserName",
data: "{}",
dataType: "json",
success: dd,
error: function(x, e) {
alert("e")
}
});
});
function dd(result) {
alert(result.d)
}
</script>
转载于:https://www.cnblogs.com/anyan/archive/2011/11/23/2310129.html