Java Questions
Java Questions

Reputation: 7953

File upload using jquery-ajax in spring

i want to upload a file to server WEB-INF/attachments using jquery ajax or any other mechanism, Because i have to upload the file without refreshing the page. I have been goggling but not found any which will help me.

Please help me as i am struggling with this for two days.

I am sure that this question will bring me many down votes and request to close also but don't know other than asking here. :(

Best Regards

Upvotes: 0

Views: 814

Answers (1)

Denis Nikanorov
Denis Nikanorov

Reputation: 832

You can use this: Create form with attribute target='file_upload_iframe'. Create iframe with attribute name='file_upload_iframe'. The form will be submitted into the iframe and response of the POST request will be in the iframe. So you can check with jquery what in response (error, sucess or smth else) and show the message to user. Also you need to hide your iframе on production, but for debug you can display it. It's very useful.

And you can use something like this to check upload result:

$('document').ready(function()
{
    $('iframe#file_upload_iframe').load(function()
    {
       callback(this);
    });
});

Pluses: This is crossbrowser method as I know.

Minuses: The loading icon of browser tab will appear, but it is not so terribly, IMHO.

P.S. Also you can use plugins http://blueimp.github.com/jQuery-File-Upload/ 7 trusted ajax file upload plugins using jquery

But some of them use flash...

Upvotes: 2

Related Questions