1》Front desk
First you need the Jquer package
<script src="js/jquery-1.9.1.js" type="text/javascript"></script> 下面是 <script type="text/javascript"> $(function () { $('#txtUserName').blur(function () { var username = $(this).val(); $.ajax({ type: "post", contentType: "application/json",//传值的方式 url: "WebAjaxForMe.aspx/GetValueAjax",//WebAjaxForMe.aspx为目标文件,GetValueAjax为目标文件中的方法 data: "{username:'" + username + "'}",//username 为想问后台传的参数(这里的参数可有可无) success: function (result) { alert(result.d);//result.d为后台返回的参数 } }) }) }) </script> //这里是参数的来源 <input id="txtUserName" type="text" />
2》Backstage
In the background, you must first add the reference of using System.Web.Services;
[WebMethod]//方法前边必须添加 [WebMethod] public static string GetValueAjax(string username)//这个方法需要是静态的方法要用到关键字static { //在这里可以对传进来的参数进行任何操作 return username; }
For more related articles on how asp.net uses Ajax and Jquery to pass parameters from the foreground to the background and return values, please pay attention to the PHP Chinese website!