10

Possible Duplicate:
How can I upload files asynchronously with JQuery?

I have a file upload field, after the image was selected, I make a jquery ajax post to an aspx page's page method. My question is, how can I pass that image via jquery? When I do $(this).val() it only gets the file name. I want to pass the image object itself.

Milad Rashidi
  • 1,296
  • 4
  • 22
  • 40
phteven
  • 1,383
  • 2
  • 16
  • 29

2 Answers2

0

You can't do that via AJAX, because file uploads are not supported by the basic XMLHttpRequest mechanism. What you have to do (either yourself or with one of various plugins that help) is post the form like a plain old form, and either target it at a hidden (or visible) <iframe> or simply reload your whole page.

Pointy
  • 405,095
  • 59
  • 585
  • 614
0

You cannot upload a file using AJAX.

Instead, you can make an <iframe> with a simple <form> tag that has nothing but a file upload and submits to a page that renders a <script> tag that calls back into the parent page with the server's response.

You can then submit the form in the <iframe> using Javascript from the parent page.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 1
    Or you can have a `
    ` in the main page with a "target" attribute that refers to an `
    – Pointy Oct 06 '10 at 03:21
  • Thanks for the reply. So you're saying i make a page with the file upload fields, embed that as an iframe on my main page? – phteven Oct 07 '10 at 17:03
  • Yes. It doesn't need to have anything other than the ``. (You can interact with it using Javascript) – SLaks Oct 07 '10 at 17:08