开发者

How to ajax post an image to a C# web method with jquery [duplicate]

开发者 https://www.devze.com 2023-01-18 17:53 出处:网络
This question already has answers here: Closed 开发者_运维知识库12 years ago. Possible Duplicate:
This question already has answers here: Closed 开发者_运维知识库12 years ago.

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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消