...

View Full Version : Using Ajax To Upload files!!Need Help



Sandeep2010
01-04-2011, 11:17 PM
Please help me with Ajax file upload.Is it possible to upload a file to the server using ajax with this method? I am using the following piece of code:



<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!

try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;

}

}


ajaxRequest.open("POST","upload.php", true);
ajaxRequest.setRequestHeader("Content-type","application/x-www- form-urlencoded");
ajaxRequest.send();
}

//-->
</script>

What should be inside send() within :ajaxRequest.send()???
The input field name for file is file[]. I am uploading multiple files.
upload.php contains code to upload files.When I am using the script without ajax(by using action="upload.php" directly in form) it works.But when I use ajax it does not work.
Please help me.
Thanks! :-)

devnull69
01-05-2011, 07:50 AM
No, unfortunately file upload is not part of ajax functionality for security reasons. All file uploads have to be started by a user with the usual browser button.

Sandeep2010
01-05-2011, 08:08 AM
No, unfortunately file upload is not part of ajax functionality for security reasons. All file uploads have to be started by a user with the usual browser button.

Thanks for the insight.But Can you please help accomplish file upload without refreshing the page?I have seen in many sites that they use ajax to accomplish this.Can you please suggest any idea?

Sandeep2010
01-05-2011, 11:34 AM
Can Anyone Help me out please?

devnull69
01-05-2011, 12:01 PM
I have seen in many sites that they use ajax to accomplish this
Most likely they used Flash, because it just isn't possible with Ajax.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum