1

Is it possible to post a <input type=“file” id="file" /> using this:

$.post("_sys/cmd.php", { file: $("#file").val() },
            function(data){
                if (data == "Success") {
                    $("#warn").html("<em>File Uploaded!</em>");
                }
});

Tried using $("#file").val() but no joy.
If it isn't possible, is there another way? Thanks. :)

Laurence Burke
  • 2,348
  • 14
  • 26
Joey Morani
  • 25,431
  • 32
  • 84
  • 131
  • 1
    possible duplicate of http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery – Laurence Burke Dec 29 '11 at 18:53
  • Ah. So even if I didn't want to upload the file using jQuery, it's not possible without one of those plugins? I only want to pass the upload info to another PHP script using jQuery. Thanks :) – Joey Morani Dec 29 '11 at 20:00

1 Answers1

1

Yes, it is possible. You just need the jQuery Form Plugin. The code will be something like it:

<script type="text/javascript"> 
    $(document).ready(function() { 
        $('#form_upload').ajaxForm(function() { 
            alert("Thank you for your upload!"); 
        }); 
    }); 
</script> 
Glauco Vinicius
  • 2,527
  • 3
  • 24
  • 37