Web Layer Improvement II-complex form submission with xmlhttp without sound information _ javascript skills

Source: Internet
Author: User
Web Layer Improvement II-using xmlhttp to submit complex forms without sound information xmlhttp is the best way to keep B/S programs away from refreshing pages for every action before the RIA era is approaching, it is also the most common technology.
HelloWord.
However, most xmlhttp applications only pass a few variables in the URL in Get mode. In fact, for a Form with a large amount of data
Javascript is encapsulated with a little bit. Similarly, you can use xmlhttp to complete the submission, which truly makes the user feel at home. When the page itself does not need to be refreshed
, Never refresh the interface of the user.
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 objects in the form, assembles the form_value string, and sends it to the Service in POST mode (not limited by the length) using the send () method.
Device.
It is a classic Chinese encoding problem, you need to add a URLEncoding function to variable value string into the UTF-8 format, so you need to use their 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) <& HFF Then
StrReturn = strReturn & ThisChrElse
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 IfNext
URLEncoding = strReturn
End Function
Server
There is nothing special to do, such as a frequent response to requests.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.