采用Microsoft.XMLHTTP提交数据的形式实现客户端无刷新
以下为引用的内容:
<SCRIPT LANGUAGE="vbScript"> dim i,strReturn function xmlhttp_submit(form_object,url) alert("") for i = 0 to form_object.elements.length-1 set elem = form_object.elements(i) form_value=form_value & URLEncoding(elem.name) & "=" & URLEncoding(elem.value) &"&" Next
set xmlhttp = CreateObject("Microsoft.XMLHTTP") xmlhttp.open "POST",url,false xmlhttp.setRequestHeader "CONTENT-TYPE","application/x-www-form-urlencoded"
xmlhttp.send(form_value) ysinfo.innerHTML=form_value msg.innerHTML=xmlhttp.ResponseText end function '上面这段代码遍历了form里的对象,组装出form_value字串,然后通过send()方法以POST方式(不受长度限制)发送给服务器端。 '又是经典的中文编码问题,需要加多一个URLEncoding函数把变量值的字符串编成UTF-8格式,也因此要采用自己不熟悉的VBScript来写form_submit() 。
Function URLEncoding(vstrIn)
strReturn = ""
For i = 1 To Len(vstrIn) ThisChr = Mid(vStrIn,i,1) If Abs(Asc(ThisChr)) < &HFF Then strReturn = strReturn & ThisChr Else innerCode = Asc(ThisChr) If innerCode < 0 Then innerCode = innerCode + &H10000 End If Hight8 = (innerCode And &HFF00)\ &HFF Low8 = innerCode And &HFF strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8) End If Next URLEncoding = strReturn End Function
</SCRIPT>
|