• Our new ticketing site is now live! Using either this or the original site (both powered by TrainSplit) helps support the running of the forum with every ticket purchase! Find out more and ask any questions/give us feedback in this thread!

Calling JavaScript programmers

Status
Not open for further replies.

najaB

Veteran Member
Joined
28 Aug 2011
Messages
32,267
Location
Scotland
I'm banging my head against something, hope someone can tell me where I'm going wrong.

I'm trying to use an xmlhttp object to POST some form data, but no matter what I do it sends the data as a multi-part form rather than URLencoding it.

Code:
var formData = new FormData();

formData.append("username", "Groucho");
formData.append("accountnum", 123456); // number 123456 is immediately converted to a string "123456"

var request = new XMLHttpRequest();

request.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            //var myArr = JSON.parse(this.responseText);
            //myFunction(myArr);
            document.getElementById("id01").innerHTML = this.responseText;
            alert(this.responseText);
        };
    }

request.open("POST", "hello.asp");
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send(formData);

When print out Response.Form (yes, Classic ASP) it is a multipart form:

Code:
------WebKitFormBoundarykSkKTglESpQu7lHa Content-Disposition: form-data; name="username" Groucho ------WebKitFormBoundarykSkKTglESpQu7lHa Content-Disposition: form-data; name="accountnum" 123456 ------WebKitFormBoundarykSkKTglESpQu7lHa-- ------WebKitFormBoundarykSkKTglESpQu7lHaContent-Disposition:form-data;name:= "username"Groucho------WebKitFormBoundarykSkKTglESpQu7lHaContent-Disposition:form-data;name="accountnum"123456------WebKitFormBoundarykSkKTglESpQu7lHa--

Thoughts?
--- old post above --- --- new post below ---
So, (sorry, just had to) after figuring out the right Google search terms it turns out that FormData objects are *always* sent as multipart forms. It would have been nice if this was included in the documentation. #rage
 
Status
Not open for further replies.

Top