I am using the $.fileDownload
Plugin from John Culviner, my goal is to download a file which is located on a server. I am using ASP.NET Web Forms. Here is my code which I use.
My JavaScript code is this
$("#btnDownload").click(function () {
$.support.cors = true;
$.ajax({
type: "GET",
url: "http://localhost/GetData/9",
processdata: false,
success: function (msg) {
$.fileDownload("http://localhost/fileDownload.txt", {
successCallback: function (url) {
alert('You just got a file download dialog or ribbon for this URL :' + url);
},
failCallback: function (html, url) {
alert('Your file download just failed for this URL:' + url + '\r\n' +
'Here was the resulting error HTML: \r\n' + html);
}
}
});
});
My "ServerCode" a WCF Webservice
[WebInvoke(UriTemplate = "GetDaten/{value}", Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
public void GetData(string value)
{
HttpContext.Current.Response.SetCookie(new HttpCookie("fileDownload", "true") { Path = "/" });
HttpContext.Current.Response.ContentType = "text/plain";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=fileDownload.txt");
HttpContext.Current.Response.WriteFile(HttpContext.Current.Server.MapPath("~/fileDownload.txt"));
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
Can someone say me what I have configure wrong, the $.fileDownload method jump always in the failCallback method.