json cmd over http |
<html> <meta charset="utf-8" /> <head> <title>Call webservice via ajax</title> <script> var xhr = new XMLHttpRequest(); function sendMsg() { var name = document.getElementById('name').value; //服务的地址 var wsUrl = 'http://192.168.0.24:4888'; //请求体 var param = '{"command":"API_start","ver":"1.1"}'; //打开连接 xhr.open('POST', wsUrl, true); //重新设置请求头 xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); //xhr.setRequestHeader("SOAPAction", "http://WebXml.com.cn/getRegionCountry"); //设置回调函数 xhr.onreadystatechange = _back; //发送请求 xhr.send(param); } function _back() { if (xhr.readyState == 4) { if (xhr.status == 200) { document.getElementById('showInfo').innerHTML = xhr.responseText; } } } function sendMsg2() { } </script> </head> <body> <input type="button" value="send command" onclick="sendMsg();"> <input type="text" id="name"><br /> <div id="showInfo"> </div> </body> </html>
|