I included qz-websocket.js in my web page and tried calling deployQZ(). The output is:
Starting deploy of qz
qz-websocket.js:43 Attempting connection on port 8181
undefined
qz-websocket.js:56 Open:
qz-websocket.js:57 Event {isTrusted: true}
qz-websocket.js:127 Websocket connection successful
jquery-1.11.3.min.js:5 Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
qz-websocket.js:132 Sending {"method":"listMessages","params":["<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n [THE REST OF MY WEB PAGE'S BODY]\n</html>\n"]}
qz-websocket.js:235 Uncaught TypeError: Cannot read property 'length' of undefined
Do you have just a barebones example of using QZ Tray, or can you tell me what I'm doing wrong?
Best regards,
Nate
--
You received this message because you are subscribed to the Google Groups "qz-print" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks for such a quick response.
I hate to take up more of your time as I'm sure you're busy, but I tried implementing the basic demo and it's not working, and if I can't get QZ working by tomorrow the company I'm working for will probably ask me to take a different approach.
I have the latest version of QZ Tray installed on OS X El Capitan. I installed a Zebra LP2844 per the instructions in the wiki, and it shows up in CUPS (as 'zebra') and in Printers & Scanners (as 'zebraClass').
Here's the code I have:
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="/assets/js/qz-websocket.js"></script>
<script>
$(document).ready(function () {
console.warn('CALLING deployQZ()');
deployQZ();
window.setTimeout(function() {
console.warn('CALLING findPrinter()');
findPrinter('zebra')
}, 1000);
window.setTimeout(function() {
console.warn('PRINTING');
qz.append64("SEVMTE8hICBZT1UgQVJFIFJFQURJTkcgQSBERUNPREVE");
qz.print();
}, 5000);
});
function getCertificate(callback) {
console.warn('INSIDE getCertificate()');
$.ajax({
method : 'GET',
url : '/assets/qz_tray/digital-certificate.txt', //edit this line to match the address of your certificate
async : false,
success: callback // Data returned from ajax call should be the site certificate
});
}
function signRequest(toSign, callback) {
console.warn('INSIDE signRequest()');
var data = {
request: toSign
};
$.ajax({
url : "/packing-station/action/signQzTrayRequest",
type : "POST",
dataType: "json",
data : data,
cache : false,
async : false,
success : callback
});
}
// Upon load, the function qzReady will be called automatically.
function qzReady() {
console.warn('INSIDE qzReady()');
try {
var version = qz.getVersion(); // Validate communication
console.log('qzReady() successful. Version: ' + version);
} catch (err) {
alert("Not working! " + err);
}
}
//Automatically gets called when "qz.print()" is finished.
function qzDonePrinting() {
console.warn('INSIDE qzDonePrinting()');
// Alert error, if any
if (qz.getException()) {
alert('Error printing:\n\n\t' + qz.getException().getLocalizedMessage());
qz.clearException();
return;
}
alert('Successfully sent print data to "' + qz.getPrinter() + '" queue.');
}
function findPrinter(name) {
qz.findPrinter(name);
}
function qzDoneFinding() {
if (qz.getPrinter()) {
alert("Printer " + qz.getPrinter() + " found.");
} else {
alert("Printer not found.");
}
}
</script>
</head>
<body></body>
</html>
The output is:
http://imageshack.com/a/img910/927/02YFWr.jpg
I think the issue may be finding the printer. When I go to the demo page and click Find Printer, an alert pops up saying:
Printer found: "" after searching for "zebra"
However, when I click List All Printers, the alert shows zebra in there:
Brother_HL_6180DW_series
Brother_HL_6180DW_series__001ba9dd3fab_
zebra
Any suggestions?
Thanks again for your help,
Nate
Nate
qz.getPrinters() returns:
"Brother_HL_6180DW_series,Brother_HL_6180DW_series__001ba9dd3fab_,zebra"
New code:
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="/assets/js/qz-websocket.js"></script>
<script>
$(document).ready(function () {
console.warn('CALLING deployQZ()');
deployQZ();
window.setTimeout(function() {
console.warn('CALLING findPrinter()');
findPrinter('zebra')
}, 2000);
});
function getCertificate(callback) {
console.warn('INSIDE getCertificate()');
$.ajax({
method : 'GET',
url : '/assets/qz_tray/digital-certificate.txt', //edit this line to match the address of your certificate
async : false,
success: callback // Data returned from ajax call should be the site certificate
});
}
function signRequest(toSign, callback) {
console.warn('INSIDE signRequest() with callback' + callback);
var data = {
request: toSign
};
$.ajax({
url : "/packing-station/action/signQzTrayRequest",
type : "POST",
data : data,
cache : false,
async : false,
success : callback
});
}
// Upon load, the function qzReady will be called automatically.
function qzReady() {
console.warn('INSIDE qzReady()');
try {
var version = qz.getVersion(); // Validate communication
console.log('qzReady() successful. Version: ' + version);
} catch (err) {
alert("Not working! " + err);
}
}
function findPrinter(name) {
qz.findPrinter(name);
}
function qzDoneFinding() {
if (qz.getPrinter()) {
alert("Printer '" + qz.getPrinter() + "' found.");
} else {
alert("Printer not found!");
Printer not found!
So it looks like everything is working correctly, except for QZ actually finding the printer. It sees that the printer exists when qz.getPrinters() is called, as mentioned, but outputs the above error when I call:
qz.findPrinter('zebra')
I got rid of timeout and further simplified the test code:
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="/assets/js/qz-websocket.js"></script>
<script>
$(document).ready(function () {
console.warn('CALLING deployQZ()');
deployQZ();
});
console.warn('CALLING findPrinter()');
findPrinter('zebra')