斑马条码打印机通过js post 打印
<html lang="zh-ch">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="A sample webpage showing how to print to a Zebra printer via javascript and XMLHttpRequest">
<meta name="author" content="Robin West">
<title>HTTP Post Sample</title>
</head>
<body>
Printer IP Address: <br>
<input type="text" id="ip_addr" style="width:500px"><br><br>
Script: <br>
<textarea id="zpl" style="width:500px" rows = '20'>^XA^PW400^LL200^FO20,20^A0N,30,30^FDThis is a TEST^FS我是中文^XZ</textarea><br><br>
<button onclick="print(); return false;">Print</button>
<div id="output"></div>
<script>
function print() {
var zpl = document.getElementById("zpl").value;
var ip_addr = document.getElementById("ip_addr").value;
var output = document.getElementById("output");
var url = "http://" + ip_addr + "/pstprnt";
var method = "POST";
var async = true;
var request = new XMLHttpRequest();
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.
output.innerHTML = "Status: " + status + "<br>" + data;
}
request.open(method, url, async);
request.setRequestHeader("Content-Length", zpl.length);
// Actually sends the request to the server.
request.send(zpl);
}
</script>
</body>
</html>