1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| <!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>data</title>
</head>
<body>
<button onclick="blabla()">getSipStatus</button>
</body>
<script type="text/javascript">
function blabla(){
var xhr = new XMLHttpRequest();
return new Promise(function(resolve, reject) {
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status >= 300) {
reject("Error, status code = " + xhr.status)
} else {
resolve(xhr.responseText);
console.log(xhr.responseText)
}
}
}
url="http://192.168.10.102/bha-api/sip.cgi?action=status"
xhr.open('get', url, true)
xhr.setRequestHeader("Access-Control-Allow-Origin","http://localhost:3000")
xhr.setRequestHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
xhr.setRequestHeader('Access-Control-Allow-Headers', 'Content-Type');
xhr.send();
});
}
</script>
</html> |
Partager