View Single Post
Old 01-04-2011, 10:17 PM   PM User | #1
Sandeep2010
New Coder

 
Join Date: Nov 2010
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Sandeep2010 has a little shameless behaviour in the past
Question Using Ajax To Upload files!!Need Help

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:
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! :-)
Sandeep2010 is offline   Reply With Quote