0

I have external javascript invoice.js which calls asmx service as follows to generate and saves invoice.pdf

$.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "/CommonService.asmx/GenerateInvoice",
            data: "{}",
            dataType: "json",
            success: function (response) {
               alert('Success');
            },
            error: function (response) {
                alert('error');
            }
        }).done(function () {//this will execute after completing ajax call also u can pass the same response to this method

            var dXmlhttp;


            var colUrl = /Service.svc/json/somefunction";
            var columnData = {
                "objList": {
                    "Mappingid": mappingid,
                    "JsonArray": JsonInvoiceArray


                }
            };
            var parmColum = JSON.stringify(columnData);

            if (window.XMLHttpRequest) {
                // code for IE7+, Firefox, Chrome, Opera, Safari
                colHttp = new XMLHttpRequest();
            }
            else {
                // code for IE6, IE5
                colHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            colHttp.onreadystatechange = function () {
                if (colHttp.readyState == 4 && colHttp.status == 200) {
                    var result = JSON.parse(colHttp.responseText);

                    }
                }
            }
            colHttp.open("POST", colUrl, true);
            colHttp.setRequestHeader("Content-type", "application/json");
            colHttp.send(parmColum);
        });

In Itextsharp pdf generating code will always run alert('error'); and it wont call done(). GenerateInvoice calls asmx to create pdf and it will save pdf.

IMRUP
  • 1,463
  • 2
  • 11
  • 17
  • because your webmethod is returning an error that is why its going to error part. And also have look at the post below you will get know how done works http://stackoverflow.com/questions/14754619/jquery-ajax-success-callback-function-definition/14754681#14754681 – Manish May 03 '16 at 05:57
  • After creating pdf, it returns error. I replaced HttpContext.Current.Response.End(); with HttpContext.Current.Response.Flush(); HttpContext.Current.Response.SuppressContent = true; HttpContext.Current.ApplicationInstance.CompleteRequest(); still getting error – IMRUP May 03 '16 at 08:58
  • will you post your webmethod code? – Manish May 03 '16 at 09:19

0 Answers0