Sometimes you have to post form data in an AJAX call started from server-side ASP script (or WSH script). The following VBScript functions will return well-formed form data that you can use with the application/x-www-form-urlencoded MIME type:
Function URLEncoded(V) ' … private Dim CC,I,Enc Enc = "" For I = 1 To Len(V) CC = AscW(Mid(V,I,1)) If (CC >= 48 And CC < 58) Or (CC >= 64 And CC < 90) Or (CC >= 97 And CC < 124) Or CC = 95 Or CC = 45 Or CC = 46 Then Enc = Enc & Mid(V,I,1) Else Enc = Enc & "%" & Hex(CC) End If Next URLEncoded = Enc End Function Function CreateFormField(F,V) ' … private CreateFormField = F & "=" & URLEncoded(CStr(V)) End Function ' ' EncodeFormData: Return form data for a POST request ' ' Input: N – array of form field names ' V – array of form field values ' ' Return: encoded form data ' Function EncodeFormData(N,V) Dim I For I = LBound(N) To UBound(N) If I <> LBound(N) Then EncodeFormData = EncodeFormData & "&" EncodeFormData = EncodeFormData & CreateFormField(N(I),V(I)) Next End Function