I have to make ajax calls in for loop. ajax gives me a text/html response. Now I have to print that each response. I am doing the below code:
function printBill(printBills, lastBillNo, type,taxType,outletId,date){
var printableObjects=[];
printBills.forEach(function(data){
lastBillNo++;
console.log(JSON.stringify(data));
$.ajax({
url: contextPath+"/print/"+lastBillNo+"/"+type+"/"+taxType+"/"+outletId+"/"+date,
type: "POST",
data: JSON.stringify(data),
contentType: 'application/json',
async:false,
success:function(response){
printableObjects.push(response); // pushing response to array.
}
});
});
return printableObjects;
}
This function gives me the printableObjects as array.. now I want to print the objects inside of this object array. To print this object I am using the below code:
function printIt(printableObj){
var counter = 0;
var timer = setInterval(function(){
printContent(printableObj[counter]);
counter++;
if (counter === printableObj.length) {
console.log("clearing timer :"+counter+" length of the obj :"+printableObj.length);
clearInterval(timer);
alert("Printing done ..");
window.location.href="takeAway";
}
},500);
console.log("============");
return true;
}
function printContent(printDoc){
//console.log("Printing object is :"+el);
var restorepage = document.body.innerHTML;
var printcontent = printDoc;
document.body.innerHTML = printcontent;
window.print();
document.body.innerHTML = restorepage;
}
I am sending this print to sendToOne note. Whenever printing is happening that time my browser got struck. Please let me know any solution. No luck with me.