function Jsajax () {varCon; varXmlrequset; varAjaxcontent;//return content if(window. XMLHttpRequest) {//determine if the browser supports XMLHttpRequest class IE6 above supportXmlrequset =NewXMLHttpRequest (); } Else { //calls using the ActiveXObject class IE6 and IE5 are not supportedXmlrequset =NewActiveXObject ("microseft.xmlhttp"); } xmlrequset.open ("POST","Index.aspx/getajax",false);//Tuning MethodXmlrequset.onreadystatechange =function () {if(Xmlrequset.readystate = =4&& Xmlrequset.status = = $) { //readystate return 0: Request uninitialized 1: Server connection established 2: Request received 3: Request processed in 4: request completed and response ready//status return: "OK" 404: Page Not foundcon=Xmlrequset.responsetext; Ajaxcontent= Xmlrequset.responsetext;//Read return valuedocument.getElementById ('Test'). InnerHTML =ajaxcontent; }} xmlrequset.setrequestheader ('Content-type','Application/json; Charset=utf-8'); Xmlrequset.setrequestheader ('SOAPAction',"Getajax"); Xmlrequset.send (); returnCon; } function Jsajax () {varCon =""; $.ajax ({type:"Post", ContentType:"Application/json", URL:"Index.aspx/getajax", Data:"", DataType:"JSON", Async:false, Success:function (RESFE) {Con=RESFE.D; } }) returnCon; }
Ajax Asynchronous calling Code