生活随笔
收集整理的這篇文章主要介紹了
Ajax异步中文数据处理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
以下為index.html頁面代碼:
<html>?<head>?<meta?http-equiv="content-type"?content="text/html;charset=gb2312">?? ?</head>?<script?language="javascript">?var?xmlHttp; ?function?showCustomer(str) ?{ ?????xmlHttp=GetXmlHttpObject(); ?????if(xmlHttp==null) ?????{ ?????????alert("您的瀏覽器不支持Ajax!"); ?????????return; ?????} ?????var?url="getcustomer.asp"; ?????urlurl=url+"?q="+str; ?????urlurl=url+"&sid="+Math.random(); ?????xmlHttp.onreadystatechange=stateChanged; ?????xmlHttp.open("GET",url,true); ?????xmlHttp.send(null); ????? ?} ?function?stateChanged() ?{ ?????if(xmlHttp.readyState==4) ?????{ ?????????if(xmlHttp.status==200) ?????????{ ?????????????document.getElementById("txtHint").innerHTML=xmlHttp.responseText; ?????????} ?????????else?if(xmlHttp.status==404) ?????????{ ?????????????document.getElementById("txtHint").innerHTML="404?Not?Found"; ?????????} ?????????else?if(xmlHttp.status==403) ?????????{ ?????????????document.getElementById("txtHint").innerHTML="403?Forbidden"; ?????????} ?????????else?if(xmlHttp.status==401) ?????????{ ?????????????document.getElementById("txtHint").innerHTML="401?Unauthorized"; ?????????} ?????} ?????else ?????{ ?????????document.getElementById("txtHint").innerHTML="錯誤url?傳輸未進行"; ?????} ??} ?function?GetXmlHttpObject() ?{ ?????var?xmlHttp=null; ?????try ?????{ ?????????xmlHttp=new?XMLHttpRequest(); ?????} ?????catch(e) ?????{ ?????????try ?????????{ ?????????????xmlHttp=new?ActiveXObject("Msxml2.XMLHTTP"); ?????????} ?????????catch(e) ?????????{ ?????????????xmlHttp=new?ActiveXObject("Microsoft.XMLHTTP"); ?????????} ?????} ?????return?xmlHttp; ?} ?</script>?<body>?<select?name="customers"?onchange="showCustomer(this.value);">?????<option?value="">請選擇客戶...</option>?????<option?value="ALFKI">Alfreds?Futterkiste</option>?????<option?value="NORTS">North/South</option>?????<option?value="WOLZA">Wolski?Zajazd</option>????? ?</select>?<div?id="txtHint"><b>客戶信息將在此處列出</b></div>?</body>?</html>?
?
?
以下為getcustomer.asp代碼
?
<% ?response.Expires=-1 ?Response.CharSet?=?"GB2312" ‘注釋 中文顯示不亂碼? ?q=Request.QueryString("q") ?Response.Write("<table>") ?Response.Write("<tr><td>"&?q?&"</td></tr>") ?Response.Write("<tr><td>"&?q?&"的用戶信息</td></tr>") ?Response.Write("</table>") ?%>? ?
?
?
?
?
?
?
?
轉載于:https://blog.51cto.com/wuzexin/303473
總結
以上是生活随笔為你收集整理的Ajax异步中文数据处理的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。