Skip to content

Instantly share code, notes, and snippets.

@nifrasismail
Last active May 27, 2024 12:00
Show Gist options
  • Save nifrasismail/574554b3dcabcf6fb13edf6a541b1501 to your computer and use it in GitHub Desktop.
Save nifrasismail/574554b3dcabcf6fb13edf6a541b1501 to your computer and use it in GitHub Desktop.
var reponseArray = [];
// Printing Job
async function printer(barcode,productLine,numberOfCopies,rcvdDate) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", '/barcode/get-script-url?barcode='+barcode+'&productLine='+productLine+'&numberOfCopies='+numberOfCopies+'&rcvdDate='+rcvdDate+'', false); // false for synchronous request
xmlHttp.send(null);
var response = await xmlHttp.responseText;
var responseObj = JSON.parse(response);
loadScript(responseObj.scripturl, function () {
window.jsWebClientPrint.print('useDefaultPrinter=true' + '&printerName=' + $('#installedPrinterName').val());
});
}
// Loading the printing script
async function loadScript(url, callback) {
var script = document.createElement("script");
script.type = "text/javascript";
if (script.readyState) {
script.onreadystatechange = function () {
if (script.readyState == "loaded" ||
script.readyState == "complete") {
script.onreadystatechange = null;
callback();
}
};
} else {
script.onload = function () {
callback();
};
}
script.src = url;
await document.getElementsByTagName("head")[0].appendChild(script);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment