Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Upload file: several times of clicking before upload window shows

Posted on 2010-11-27
7
490 Views
Last Modified: 2012-05-10
Hi all,

Please help me to fix the code below. It uploads files to the server using AjaxUpload.2.0.min.js

You need to click several times on the “Add File” button for the OS window (where to pick the file you want to upload) to show.

Why several times? It has to open with the first click, then what am I doing wrong?

Please focus on this, on the OS window to show with the first click of the mouse. The rest of the programming it's working fine in my server.

Thanks a lot
<html>
<head>
<style>
#upload_files{color: #fff; background:#F32201; border:1px solid #7E9DB9; padding:2px;}
</style>
   
<script type="text/javascript" src="https://gist.github.com/raw/6dd585079502f138d87e/7c243080233761859937d52195b670602731a379/jquery-1.4.2.min.js"></script>
                                       
<script type="text/javascript" src="https://gist.github.com/raw/eeb2fe78f63ab80b626d/5be66e749b19fbb5b7c8814bf72a98c083f2aaaf/jquery.livequery.min.js"></script>
   
<script type="text/javascript" src="https://gist.github.com/raw/826bff2445c8533dd7fc/797734455959ef27796b6770c95a7b39049ae6e9/AjaxUpload.2.0.min.js"></script> 
       	         
          
<script type="text/javascript">
$(document).ready(function() {

function uploadFiles(){   
/* upload the file or files */
	 
var buttoncola = $('#upload_files');		
		new AjaxUpload('#upload_files', {
			action: 'whereToUploadInServer.php',
			onSubmit : function(file , ext){
				if (! (ext && /^(csv)$/.test(ext))){
					// only .csv files
					alert('Error: just CSV');
					// cancel upload
					return false;
				} else {
					buttoncola.text('Uploading');                
					this.disable();
					$('#loader1').show();
				}
			},
			onComplete: function(file, response){
				$('#loader1').hide();
				buttoncola.text('Add File');
				// enable upload button
				this.enable();			
				// add file to the list								
				$('#list').fadeIn(200).html('').append('<div id="mycola">File added: '+file+ ' '+response+'</div>');
				return false;
			}
		});		
	
	}//end function
	
	       $("#upload_files").livequery("click", function(e){
        e.preventDefault();
        uploadFiles();
    }); 
	

      }); //end document ready

    </script>
    
 
  </head>
  <body>
       <div><a href="#" id="upload_files">Add File</a></div> <br>
       <div id="list"></div>
  </body>
</html>

Open in new window

0
Comment
Question by:Dada44
  • 4
  • 3
7 Comments
 
LVL 29

Expert Comment

by:Badotz
ID: 34222506
First thing I would do is download jQuery to your local server. That will eliminate any cloud-related problems.
0
 

Author Comment

by:Dada44
ID: 34222852
Thanks for answering Badotz.

All the .js are in my server, the way I have linked them in the here is just to make it easy for you to copy and paste in an editor and see what is happening in case you want to do it.

With all the .js in my server (and even locally) the several clicks are needed :(
0
 
LVL 29

Expert Comment

by:Badotz
ID: 34222871
I would place a breakpoint ( the keyword [b]debugger[/b] ) on a separate line in the event handler and enable Firebug. That takes out all of the guesswork we must do, and you can step through the code and see what is happening.

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 29

Accepted Solution

by:
Badotz earned 500 total points
ID: 34222873
And the keyword is, of course, debugger;
0
 

Author Comment

by:Dada44
ID: 34224836
You are right, the problem is in the event handler,  but I cannot detect what is it exactly the bug.

If I get rid off :
 
             $("#upload_files").livequery("click", function(e){
        e.preventDefault();
        uploadFiles();
    });

And I delete: function uploadFiles(){ and } it works, but why not with the function ?

Thanks again
0
 

Author Closing Comment

by:Dada44
ID: 34224886
thanks, I've found not an ajax issue anymore
0
 
LVL 29

Expert Comment

by:Badotz
ID: 34225457
No worries - glad to help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question