I'm trying to print qz tray from javascript. I have barcode with number in ascending order 1,2,3,4, 5 and so on. I looping the seq correctly . but when printed out, it was not in order.
setTimeout("directPrint2()",1000);
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
function directPrint2(){
var data;
var xhttp;
var v_carton = "' || x_str_carton ||'";
var carton_arr = v_carton.split('','');
var v1 = "' ||
replace(x_zebra_printer_id, '\', '|') ||
'".replace(/\|/g,"\\");
if(v1 == ""){
alert("Please setup ZPL Printer");
}
else{
xhttp=new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
data = [ toNative(this.responseText) ];
printZPL(data, v1);
}
};
for (var j = 0; j < carton_arr.length; j++){
var url = "' || x_wms_url ||
'WWW_URL.direct_print_label?in_carton_no="+toValidStr(carton_arr[j]);
xhttp.open("GET", url, false);
xhttp.send();
sleep(5000);
}
}
};
',
'javascript'
What's missing from your example:
printZPL
function,printZPL
isn't a QZ Tray function and you're missing the code snippet which it calls. Usually this would beqz.print(config, data);
.Regardless of the missing information, the
qz.print(...)
API is ES6/Promise/A+ based meaning if you want to callqz.print
multiple times in a row you need to use a Promise-compatible technique. (e.g..then(...)
syntax) between your print calls as explained in the Chaining Requests guide.To avoid this, you can concatenate all ZPL data into one large
data
array. Be careful not to spool too much data at once.If you know exactly how many jobs you'll be appending, you can hard-code the promise chain:
Finally, if you do NOT know in advanced how many calls to
qz.print(...)
you can use a Promise loop as explained in the Promise Loop guide.Note: The Promise Loop is no longer needed in QZ Tray 2.1. Instead, since 2.1, an array of
config
objects anddata
arrays can be provided instead.