Side navigation
#9995 closed feature (wontfix)
Opened August 07, 2011 06:15PM UTC
Closed August 07, 2011 06:36PM UTC
Last modified August 07, 2011 06:49PM UTC
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: | ||
Blocked by: | Blocking: |
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?
Attachments (0)
Change History (3)
Changed August 07, 2011 06:36PM UTC by comment:1
component: | unfiled → ajax |
---|---|
priority: | undecided → low |
resolution: | → wontfix |
status: | new → closed |
Changed August 07, 2011 06:46PM UTC by comment:2
OK, I'll look into this "ajax prefilter" thing... :)
Thank you.
Changed August 07, 2011 06:49PM UTC by comment:3
You're welcome
Also, this might help: http://api.jquery.com/extending-ajax/#Prefilters
You could very easily create an ajax prefilter to achieve this functionality without adding anything to the jQuery core.