Does anyone know of a way to pass uploaded files from forms using AJAX/JavaScript?
I sense the problem is in the javascript (which is why I'm posting it here). Here's the code:
Code:
// declaring javascript variable (in .js file) for uploaded file with form name
// 'userfile1'
var postUserfile1 = theForm.userfile1.name + "=" + encodeURIComponent( theForm.userfile1.value );
// calling makeRequest function to pass variable to AJAX request
makeRequest(url, postUserfile1);
And finally, here's the makeRequest function:
Code:
//Initiate the AJAX request
function makeRequest(url, param) {
//If our readystate is either not started or finished, initiate a new request
if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
//Set up the connection to captcha_test.html. True sets the request to asyncronous(default)
receiveReq.open("POST", url, true);
//Set the function that will be called when the XmlHttpRequest objects state changes
receiveReq.onreadystatechange = updatePage;
//Add HTTP headers to the request
receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
receiveReq.setRequestHeader("Content-length", param.length);
receiveReq.setRequestHeader("Connection", "close");
//Make the request
receiveReq.send(param);
}
}
thanks all!
sage
|