1 "Front desk"
First you need a Jquer package.
<script src= "Js/jquery-1.9.1.js" type= "Text/javascript" ></script>
Below is
<script type= "Text/javascript" >
$ (function () {
$ (' #txtUserName '). blur (function () {
var username = $ (this). Val ();
$.ajax ({
Type: "Post",
ContentType: "Application/json",//way of passing values
URL: "Webajaxforme.aspx/getvalueajax",//webajaxforme.aspx as the target file, Getvalueajax as the method in the target file
Data: "{username: '" + Username + "'}",//username to ask background pass parameters (here the parameters are optional)
Success:function (Result) {
alert (RESULT.D);//result.d returned parameters for the background
}
})
})
})
</script>
Here's the source of the argument.
<input id= "txtUserName" type= "text"/>
2 "Backstage
In the background, first add a using System.Web.Services reference
[WebMethod] must be added at the front of the webmethod]//method
public static string Getvalueajax (string username)//This method requires a static method to use the keyword static
{
You can do anything with the incoming parameters here.
return username;
}