Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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! :-)

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    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.

  • #3
    New Coder
    Join Date
    Nov 2010
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by devnull69 View Post
    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?

  • #4
    New Coder
    Join Date
    Nov 2010
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Can Anyone Help me out please?

  • #5
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Quote Originally Posted by Sandeep2010 View Post
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •