Ticket #9995 (closed feature: wontfix)
How to send FormData objects with Ajax-requests?
| Reported by: | sime.vidas | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | None |
| Component: | ajax | Version: | 1.6.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I am using FormData instances to append files to Ajax-requests. It works like so:
var xhr = new XMLHttpRequest(),
fd = new FormData();
fd.append( 'file', input.files[0] );
xhr.open( 'POST', 'http://example.com/script.php', true );
xhr.onreadystatechange = handler;
xhr.send( fd );
I would like to do this using jQuery's Ajax-methods, but it doesn't seem to work. I tried this:
var fd = new FormData(); fd.append( 'file', input.files[0] ); $.post( 'http://example.com/script.php', fd, handler );
but I get an illegal invocation error.
Btw, I've laid out this issue in [this StackOverflow question]( http://stackoverflow.com/questions/6974684/how-to-send-formdata-objects-with-ajax-requests-in-jquery).
Can this be done in jQuery?
Change History
comment:1 Changed 22 months ago by rwaldron
- Priority changed from undecided to low
- Resolution set to wontfix
- Status changed from new to closed
- Component changed from unfiled to ajax
comment:2 Changed 22 months ago by sime.vidas
OK, I'll look into this "ajax prefilter" thing... :)
Thank you.
comment:3 Changed 22 months ago by rwaldron
You're welcome
Also, this might help: http://api.jquery.com/extending-ajax/#Prefilters
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

You could very easily create an ajax prefilter to achieve this functionality without adding anything to the jQuery core.