Zebra Javascript printing status from printer

Hello guys!

 

Using the web developing guide that Robin provided (link incoming..), I am trying to make an application so I can print some labels with user input. For now it is working fine, but if I wanna share this application with other people, so I would like there to be a button in my application so people can test their printer, because I can already predict that a lot of people are going to fill in a wrong IP or someting like that.

 

What I would like their to be is a command so I can get get a response from the printer, and thus check if the printer is connected, it is online etc. Is there any ZPL command or other way to do this?

 

My code:

 

        var ip_addr = "192.168.254.111"

        var url = "http://" + ip_addr + "/pstprnt";

        var async = true;

        var method = "POST";

        var zpl = "^XA^FO20,10^AD^FDTest^FS^FO20,60^B3^FDAAA001^FS^XZ";

        var request = new XMLHttpRequest();

 

        request.onload = function () {

            var status = request.status;

            var data = request.responseText;

        }

 

        request.open(method, url, async);

        request.send(zpl);

 

This works fine, and I can print labels, but I do not receive any response in the status en data variable, so in my application I can never confirm if the label has been  printed.

 

Thanks!

Anonymous (not verified)
Hi Nick,You've hit on one of

Hi Nick,

You've hit on one of the major drawbacks of the way this work in our printers.  The only responses you can get are simple 200 responses.  This is what you should be getting in the "var status" in the request.onload function.  You can verify something is at that address.  If you want to verify it's a zebra printer and maybe scrape some useful current status info, you can post to the printer webpage.  This is not a fail-safe and I've had issues with not getting any response on Chrome (I'm guessing it may be blocked in some circumstances)

    function verify()

    {

      var ip_addr = "192.168.254.111";

      var output = document.getElementById("output");

      var url = "http://"+ip_addr+"/index.html";

      var method = "POST";

      var async = true;

      var request = new XMLHttpRequest();

      var message = "";

      request.onload = function () {

        var status = request.status; // HTTP response status, e.g., 200 for "200 OK"

        var data = request.responseText; // Returned data, e.g., an HTML document.

        var printStatus = data.substr(data.indexOf("Status:") - 4);

        printStatus = printStatus.substring(0, printStatus.indexOf("</H3>") + 5);

        var printer = data.substr(data.indexOf("Zebra Technologies") - 4);

        var printer = printer.substring(0,printer.indexOf("/") + 4);

        output.innerHTML = printer + printStatus;

      }

      request.open(method, url, async);

      // Actually sends the request to the server.

      request.send(message);

    }

I can't guarantee this scraping will work with every printer, the pages have changed some over time, but you can work with it to get some better ideas. I'm sure there's an easier javascript or jquery way to get the correct elements.

The lack of 2-way communication is one of the many reasons we created Browser Print.​ I'm still highly encouraging people to try switching to Browser Print if at all possible, as we can't guarantee if or when the HTTP post method will be blocked by different browsers for security.

Robin West

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Nick van de Lui...
Thanks for your response!I

Thanks for your response!

I think I am gonna use Browser Print, it looks pretty good. Does Browser Print also work if we put our application on a server and access it from the domain (e.g. zebra.mycompany.nl)?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Daniel Wiesmann
I am using ZD410, and trying

I am using ZD410, and trying to print using JS very similar the stuff I've found posted in these messages.

My problem is not with the printing of the labels, those get printed ok.

My problem is that the printer NEVER responds to the POST messages. No 200, no 500, just no answer whatsoever.

Is this a known issue with a workaround?

Thanks,

Daniel

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Daniel, Yes we do find

Hi Daniel, Yes we do find this happens sometimes.  My GX420d does not show any response (200 or otherwise) in Chrome but does in IE.  I assume it has to do with updates to HTTP standards.  There is no work around for it using the POST methods as it seems to be controlled by the browser.  Yet another reason to try Browser Print...   Sorry.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments