简体   繁体   中英

Javascript form won't submit

I have been using the uploader as provided by http://www.hoppinger.com/blog/2010/05/28/file-upload-progress-bar-with-phpapc-and-javascript/ and have since applied it to one of my forms and whilst the progress meter works, the submit function doesn't fire on successful upload.

The full code of what I am using is below:

JS
get_progress.php
uploader.php

As far as I can tell, in my limited experience, this is the function that handles the submit:

postUpload : function(o_data)
{
    // Loop through every input and set json response in hidden input
    this.a_inputs.each((function(o_input)
        {
            var s_name = o_input.get('name');
            var s_value = '';

            if(o_file = o_data.files[s_name])
            {
                s_value = JSON.encode(o_file);
            }


            var o_jsonInput = new Element('input',{'type': 'hidden','name':o_input.origName,'value':s_value}).replaces(o_input);


        }).bind(this));

    // Make form "original" again by purging elements and resetting attributes
    this.revertSubmit();
    this.o_form.submit();
},

I noticed that the submit was this.o_form.submit(); rather than this.form.submit(); and checked it out and he has declared o_form : {} at the top of the class, so I assume that his syntax is correct but I have no real idea.

Prior to my implementing this progress tracker the form worked perfectly, so this has got me quite frustrated.

Essentially what has gone wrong, I can only assume that it's something as simple as a missing ; or similar mistake.

If you get a 404 on the submit that means it worked. I have temporarily unblocked the page for troubleshooting.

As it may be relevant, my site uses WordPress.

It turned out that the javascript wasn't adding the APC_UPLOAD_PROGRESS tag to the form so I added the following jQuery after the initilisation:

<script type="text/javascript">
    jQuery(document).ready(function(){

        var id = jQuery("form").attr('id');

        jQuery("form").submit(function(){

            jQuery(this).append("<input type=\"hidden\" name=\"APC_UPLOAD_PROGRESS\" value=\""+id+"\" />");

        });

    });

</script>

And now it's all good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM