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.