title: Epson thermal printer javascript
body: <p>I'm trying to use an Epson TM-T20II (thermal printer) via a web page. I've done the necessary configuration and the printer works fine on my network using the given software. So I downloaded the JS epos print SDK, and tried to run this sample code : </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8" /&gt;
      &lt;title&gt;TITLE&lt;/title&gt;
      &lt;script type="text/javascript" src="../ePOS-Print_SDK/ePOS-Print_SDK_150729E/JavaScript/epos-print-5.0.0.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
           function buildMessage() {
               //Create an ePOS-Print Builder object
               var builder = new epson.ePOSBuilder();
               //Create a print document
               builder.addTextLang('en')
               builder.addTextSmooth(true);
               builder.addTextFont(builder.FONT_A);
               builder.addTextSize(3, 3);
               builder.addText('Hello,\tWorld!\n');
               builder.addCut(builder.CUT_FEED);
               //Acquire the print document
               var request = builder.toString();
               var address = 'http://192.168.1.65/cgi-bin/epos/service.cgi?devid=99&amp;timeout=1000';
               //Create an ePOS-Print object
               var epos = new epson.ePOSPrint(address);
               epos.onreceive = function (res) {
               //When the printing is not successful, display a message
               if (!res.success) {
                  alert('A print error occurred');
                  }
               }
               //Send the print document
               epos.send(request);
           }
      &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
       &lt;button onclick='buildMessage()'&gt;Run&lt;/button&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>For the devid parameter I tried 'local_printer' which is the name of the device,
  then I saw in the configuration panel that the printer id is 99. Still, it doesn't work, I got a 405 Method not allowed status code on the cgi request.</p>
  
  <p>Any tips ? Thanks in advance.</p>
  
  <p>EDIT :</p>
  
  <p>So, after some research, it seems that the problem comes from a CORS request. The request is preflight for security matters, and this preflight request doesn't pass acces control cause the 'Access-Control-Allow-Origin' header is missing from the response. So how do I set this header ?</p>