Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#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:
Blocked by: Blocking:


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 (3)

comment:1 Changed 11 years ago by Rick Waldron

Component: unfiledajax
Priority: undecidedlow
Resolution: wontfix
Status: newclosed

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

comment:2 Changed 11 years ago by sime.vidas

OK, I'll look into this "ajax prefilter" thing... :)

Thank you.

comment:3 Changed 11 years ago by Rick Waldron

You're welcome

Also, this might help: http://api.jquery.com/extending-ajax/#Prefilters

Note: See TracTickets for help on using tickets.