Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Generating word document using WebMethod and Jquery AJAX Call.

$
0
0

[WebMethod()]
    public static string SaveRequest()
    {
        StringWriter _writer = new StringWriter();
        HttpContext.Current.Server.Execute("frmGenerateRequests.aspx", _writer);
        string html = _writer.ToString();
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Charset = "";
        HttpContext.Current.Response.ContentType = "application/msword";
        string strFileName = "GenerateDocument" + ".doc";
        HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);
        StringBuilder strHTMLContent = new StringBuilder();
        strHTMLContent.Append(html.ToString());
        HttpContext.Current.Response.Write(strHTMLContent);
        //HttpContext.Current.Response.End();
        HttpContext.Current.ApplicationInstance.CompleteRequest();
        HttpContext.Current.Response.Flush();
        return "Success";
    }

JQuery Call:

$.ajax({
        type: "POST",
        url: 'frmRequest.aspx/SaveRequest',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            
        },
        failure: function (errMsg) {
            alert('failed saving Quotation Request ' + errMsg);
        },
        error: function (response) {
            alert('Error in saving Quotation Request ' + response.d);
        }
    });

If I use the same code in non-static method its working fine. But its not throwing any execption also.

I need to generate document by using AJAX Call only.

Thanks in advance:-)


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>