1

Is this possible to send image or video file through jquery ajax post method?yes or no?

 $.ajax({
            type: 'POST',
            url: "url?json",
            data: {image:},
            success: function (o) {

            },
            dataType:"json"
     });
4

1 回答 1

0

No. Uploading a file need a full postback.

You can simulate an ajax call posting to a hidden iFrame (so your page don't change). Then checking the content of the iFrame using jquery/javascript you can see if the upload was successful and do a refresh of certain part of your screen.

If you are using ASP.NET MVC3 or MVC4 here is an example (I'm using this): http://www.dustinhorne.com/post/2011/11/16/AJAX-File-Uploads-with-jQuery-and-MVC-3.aspx

If you want a more generic way of doing it in JS: http://tips.itliveweb.com/ajax/upload-image-using-iframe-javascript-ajax.html

于 2013-01-15T14:48:02.127 回答