第一種,先看VBA
Public Function GetInfo(strMoblie As String) As String '創建對象 Dim xmlHttp As Object Set xmlHttp = CreateObject("MSXML2.XMLHTTP") '發送請求 xmlHttp.Open "GET", "http://www.ip138.com:8080/search.asp?action=mobile&mobile=" & strMoblie, False xmlHttp.Send '等待響應 Do While xmlHttp.ReadyState <> 4 DoEvents Loop '得到請求數據 Dim strReturn As String strReturn = xmlHttp.ResponseText GetInfo = strReturn End Function
第二種,XML Http Request,是不是似曾相識呀
<html> <head> <script type="text/javascript"> xmlHttp=null; function showHint(str) { if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } try {// Firefox, Opera 8.0+, Safari, IE7 xmlHttp=new XMLHttpRequest(); } catch(e) {// Old IE try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { alert ("Your browser does not support XMLHTTP!"); return; } } url="/ajax/gethint.asp?q=" + str; url=url+"&sid="+Math.random(); xmlHttp.open("GET",url,false); xmlHttp.send(null); document.getElementById("txtHint").innerHTML=xmlHttp.responseText; } </script> </head> <body><form> First Name: <input type="text" id="txt1" onkeyup="showHint(this.value)"> </form><p>Suggestions: <span id="txtHint"></span></p> </body> </html>
這個先放着,回頭補充。
