Download a file from server using jQuery Ajax

Posted by Jpchoudhari under ASP.NET AJAX on 7/5/2012 | Points: 10 | Views : 18262 | Status : [Member] | Replies : 5
Hi,

How to download a file from server using jQuery Ajax in asp.net

Kind Regards,
Jay



Responses

Posted by: Premalatha on: 7/5/2012 [Member] Starter | Points: 25

Up
0
Down
Try it

Method

jQuery.download = function(url, data, method){
//url and data options required
if( url && data ){
//data can be string of parameters or array/object
data = typeof data == 'string' ? data : jQuery.param(data);
//split params into form inputs
var inputs = '';
jQuery.each(data.split('&'), function(){
var pair = this.split('=');
inputs+='<input type="hidden" name="'+ pair[0] +'" value="'+ pair[1] +'" />';
});
//send request
jQuery('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>')
.appendTo('body').submit().remove();
};
};

How to Use It


$.download('/export.php','filename=mySpreadsheet&format=xls&content=' + spreadsheetData );


I Hope this helps

Premalatha
Software Engineer

Jpchoudhari, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jpchoudhari on: 7/6/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

thanks for your replay.

But can you tell me how to handle this request on server side in asp.net.

Kind Regards,
Jay

Jpchoudhari, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Premalatha on: 7/6/2012 [Member] Starter | Points: 25

Up
0
Down
Please go to this Link
http://www.codeproject.com/Articles/238866/Invoke-Server-Methods-From-Client-Side-Using-JQuer

Premalatha
Software Engineer

Jpchoudhari, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jpchoudhari on: 7/6/2012 [Member] Starter | Points: 25

Up
0
Down
thanks will try this

Kind Regards,
Jay

Jpchoudhari, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vinay13mar on: 10/15/2012 [Member] Starter | Points: 25

Up
0
Down
Hi.
Check the below link this will help you
http://www.dotnetpools.com/Article/ArticleDetiail/?articleId=33&title=How%20To%20Make%20Ajax%20Call%20Using%20Jquery%20in%20Asp.Net

Jpchoudhari, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response