Web layer Improve II- Submit complex form with XMLHTTP

xiaoxiao2021-03-06  35

XMLHTTP is before the RIA era, the XMLHTT is not coming, and the B / S program can be kept away from each action to refresh the painful practice, and it is also a technology for the most civilized means, and helloWord is completed. However, everyone's application of XMLHTTP is mostly transmitted in the URL in the URL in the URL. In fact, even if it is a lot of data, as long as you use JavaScript to add a slight package, you can use simple use XMLHTTTP to be submitted, truly let the guests are almost attributed, and if the page itself needs to be refreshed, never refresh the home. Interface.

Client:

Function XMLHTTP_SUBMIT (Form_Object, URL)

For i = 0 to form_Object.ements.length-1

Set elem = form_Object.eferences (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 traversed the object in the Form, and assembles the Form_Value string, and then sends it to the server side by the send () method (not limited to length restrictions).

It is also a classic Chinese coding problem, which requires a multi-URLENCoding function to compose the string of the variable value into the UTF-8 format, and therefore uses the non-familiar VBScript to write form_submit ().

Function Urlencoding (vstrin)

Strreturn = ""

For i = 1 to len (vstrin)

Thischr = MID (vstrin, i, 1)

IF ABS (ASCHR) <& HFF THEN

Strreturn = Strreturn & thischr

Else

Innercode = ASC (thischr)

IF innercode <0 THEN

Innercode = InnerCode & H10000

END IF

High8 = (InnerCode and & HFF00) / & HFF

Low8 = innercode and & hff

Strreturn = Strreturn & "%" & hex (hight8) & "%" & hex (low8)

END IF

NEXT

Urlencoding = Strreturn

END FUNCTION

Service-Terminal

There is no thing that requires special work, if the response request is.

转载请注明原文地址:https://www.9cbs.com/read-59759.html

New Post(0)