2

I have a simple form with some text inputs and a file input. I do not send it directly with a post, but I read each value of the text inputs with jQuery, compose a $.post request and send it to the server.

How can I do the same with a file <input type = "file" />? I mean, sending it via ajax to a ASP.NET MVC page?

Thanks in advance

1

2 Answers 2

4

You cannot use an xhr request to upload a file.

You have two options. Use an iframe or use a flash uploader.

See this similar question & answers.

Sign up to request clarification or add additional context in comments.

Comments

3

You can't. That would require javascript being able to read the file from your hard drive and send it to the website... the browser security model wouldn't allow for it.

You can do some javascript DOM trickery where have the file element in an iframe and use javascript to submit the form -- this is what google does with gmail. There are also flash methods of doing this.

James

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.