2

so I have a PHP iframe (ajax) file uploader. I would like to display a loading message when submit is clicked (easy on click event) and then once the file is uploaded, so when the iframe is loaded with the PHP response, vanish (jquery fadeOut) and an alert box pop up saying the file is uploaded. what would be the easiest way to go about this?

2
  • 2
    Look at Valums file uploader. Commented Nov 30, 2011 at 11:58
  • I dnt want to use a plugin, Security is too much of a risk with plugins. Commented Nov 30, 2011 at 12:23

1 Answer 1

4

You can attach an event handler to load on the iframe and put your fade out logic in there.

Edit 2: Some sample code (changed from ready to load)

<iframe name="process"></iframe>

<form method="post" action="upload.php" target="process" enctype="multipart/form-data" onsubmit="Upload.start()">
    <input type="file" name="file" />
    <input type="submit" value="Upload" />
</form>

<script>
    var Upload = function() {

        $(function() {
            $('iframe[name=process]').load(function() {
            // finished uploading file
                $('.loading-div').hide('slow', function() {
                    alert('Your file has been successfully uploaded.');
                });
            });
        });

        return {
            start: function() {
                $('.loading-div').show();
            }
        }
    }();  
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

$('iframe[name=process]').ready(function() Runs before the file has finished uploading, also I would like to give a response based on the PHP processing of the file, Which get dumped in the frame sadly
Working, Awsum, tnks soooo much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.