3

I have a <div/> tag which contains a file upload <input id="file" type="file"/> tag. I want to post the contents of the input tag to a php page using $.ajax() or $.post() but how do I grab the contents of the input tag having its type as "file"? so I can submit it using the jQuery ajax functions?

Note: My code doesn't have a <form/> tag yet. I am not sure if its mandatory to upload files. Also i've seen some workarounds using <iframe> I want to know if this can be done otherwise.

I don't want to use any plugins to do this.

1
  • this can be done with <iframe> / java applet / flash Commented Jun 1, 2011 at 7:15

2 Answers 2

2

A byte stream can't be part of an asynchronous request.

In other words, you can't send data using AJAX approaches.

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

3 Comments

True. And I've answered that because he's thinking in jQuery $.ajax or any other approach using AJAX.
@MatíasFidemraizer: This is not true. You can catch the data using "drop" event listener (e.g. on div) using event.dataTransfer.files and then create new FormData using var fd = new FormData(); fd.append("fileToUpload", fileList[i]);, create new XMLHTTPRequest and send the data: request.send(fd);.
@Julian I guess you're talking about HTML5. Feel free to edit my answer adding this info and I'll approve the edit for you.
1

you can't send file through $.post... you can use this link to uplaod file through ajax.. http://www.uploadify.com/demos/

1 Comment

Links to external site directly are not preferred on SO. You should provide in some contents first and then refer it.

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.