troubleshooting Question

JQuery upload

Avatar of tonelm54
tonelm54 asked on
jQuery
2 Comments1 Solution115 ViewsLast Modified:
Ive been struggeling to upload a file by jQuery. I want to upload the file sepretly (without having to enclose it in a form or iFrame).

So, Ive constructed the following:-
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="jquery-ui.min.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $(document).on("click","#btnUpload", function(e) {
            var fileSelect = $("#tstFile");
            var files = fileSelect.files;

            var frmData = new FormData();

            for (var i = 0; i < files.length; i++) {
                var file = files[i];
                frmData.append('tstFile[]', file, file.name);
            }

            $.ajax({
                url: 'upload.php',
                type: 'POST',
                data: frrmData,
                cache: false,
                contentType: false,
                processData: false,
                success:function(data){
                    alert(data);
                },
            });
        });
    });
</script>

    <input type="file" id="tstFile" name="tstFile" />
    <button id="btnUpload">Upload</button>

On the debugger I get "files not found", and nothing uploaded on my upload.php page into the $_FILES object.

Any ideas how to fix this?
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros