asp.net中手写ajax

    技术2022-05-20  62

    < html > < head > < title > AjaxTest </ title > < script > var xmlHttp; function createXMLHttpRequest() { if (window.ActiveXObject) { xmlHttp = new ActiveXObject( " Microsoft.XMLHTTP " ); } else if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } } function startRequest() { createXMLHttpRequest(); try { var username = document.getElementById( " <%= text1 . ClientID %> " ).value; xmlHttp.onreadystatechange = handleStateChange; xmlHttp.open( " GET " , " validname.aspx?username= " + username, true ); xmlHttp.send( null ); } catch (exception) { alert( " xmlHttp Fail " ); } } function handleStateChange() { if (xmlHttp.readyState == 4 ) { if (xmlHttp.status == 200 || xmlHttp.status == 0 ) { var param = xmlHttp.responseText; document.getElementById( " msg " ).innerHTML = param; } } } </ script > </ head > < body > < div > < input type ="type" id ="text1" />< span id ="msg" ></ span >< br > < input type ="button" value ="Test" onclick ="startRequest();" /> </ div > </ body > </ html >

     

     

    public void Page_Load() { string userName = Request.QueryString [ " username " ] ; if (iExists(userName)) { Response.Write( " 用户名存在 " ); } else { Response.Write( " 用户名可用 " ); } Response.End(); } public bool iExists( string username) {.....}

    最新回复(0)