Avatar of tonelm54
tonelm54

asked on 

JQuery upload

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>

Open in new window


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?
jQuery

Avatar of undefined
Last Comment
hielo
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

If that's a copy/paste of your code, then you have a typo:

data: frrmData,

should be:

data: frmData
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
jQuery
jQuery

jQuery (Core) is a cross-browser JavaScript library that provides abstractions for common client-side tasks such as Document Object Model (DOM) traversal, DOM manipulation, event handling, animation and Ajax. jQuery also provides a platform to create plugins that extend jQuery's capabilities beyond those already provided by the library.

19K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo