If you
Google[
^] for it then you will know that this is a common issue faced by a lot of people.
Have a look at these discussions:
jQuery AjaxUpload, have to click button twice?[
^]
Jquery form upload plugin: how to reduce it to one click?[
^]
AjaxUpload: why have to click twice?[
^]
Based on above discussions, it looks like, the reason why you needed to click several times, is because AjaxUpload() does NOT initiate a file upload. Instead, it attaches a click listener to the element you pass to it as a parameter. So, when you clicked the first time, the listener was created. The second time, the file upload was initiated. So, try:
$(function(){
AjaxUpload("#upload_files",{
});
}
Thus, when the page is loaded, the AjaxUpload plugin adds a listener to the #upload_files element, that then in turn triggers the file upload.