Home > Web Front-end > JS Tutorial > Web layer improvement II-use xmlhttp to silently submit complex forms_javascript skills

Web layer improvement II-use xmlhttp to silently submit complex forms_javascript skills

WBOY
Release: 2016-05-16 19:20:25
Original
1281 people have browsed it

Before the advent of the RIA era, xmlhttp was the best way to keep B/S programs away from the pain of refreshing the page for every action. It was also the most civilian technology
. HelloWord can complete it in just a few sentences.
However, most of the applications of xmlhttp only use Get method to pass a few variables in the URL. In fact, even if it is a Form with a large amount of data, as long as it is slightly encapsulated with
Javascript, it can be submitted simply by using xmlhttp, so that the user can truly feel at home, and the page itself does not need to be refreshed
. Never refresh the user interface.
Client:
function xmlhttp_submit(form_object,url)
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)
end function
The above code traverses the form Object, assemble the form_value string, and then send it to the server in POST mode (without length limit) through the send() method.
It’s another classic Chinese encoding problem. You need to add an additional URLEncoding function to encode the variable value string into UTF-8 format. Therefore, you have to use the unfamiliar
VBScript to write form_submit().
Function URLEncoding(vstrIn)
strReturn = ""
For i = 1 To Len(vstrIn)
ThisChr = Mid(vStrIn,i,1)
If Abs(Asc(ThisChr) ) strReturn = strReturn & ThisChrElse innerCode = Asc(ThisChr)
If innerCode innerCode = innerCode &H10000 End If
Hight8 = (inner Code And &HFF00 ) &HFF
Low8 = innerCode And &HFF
strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
End IfNext
URLEncoding = strReturn
End Function
The server side
There is nothing special that needs to be done, just respond to the request as usual.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template