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. :)

2
  • 1
    possible duplicate of stackoverflow.com/questions/166221/… Commented Dec 29, 2011 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 :) Commented Dec 29, 2011 at 20:00

1 Answer 1

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> 
Sign up to request clarification or add additional context in comments.

Comments

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.