Bekijk de onderstaande video om te zien hoe je onze site als een web app op je startscherm installeert.
Opmerking: Deze functie is mogelijk niet beschikbaar in sommige browsers.
<script type="text/javascript">
var url = "http://192.168.1.61:8090/now_playing";
var invocation = new XMLHttpRequest();
var invocationHistoryText;
function callOtherDomain(){
if (invocation) {
invocation.open('GET', url, true);
invocation.withCredentials = "true";
invocation.onreadystatechange = handler;
invocation.send();
} else {
invocationHistoryText = "Sorry. No Invocation Took Place, or Errors Took Place";
// invocationHistoryText is error
var textNode = document.createTextNode(invocationHistoryText);
var textDiv = document.getElementById("textDiv");
textDiv.appendChild(textNode);
}
}
function handler(evtXHR) {
if (invocation.readyState == 4) {
if (invocation.status == 200) {
var response = invocation.responseText;
// response is gevraagde tekst
invocationHistoryText = document.createTextNode(response);
var textDiv = document.getElementById("textDiv");
textDiv.appendChild(invocationHistoryText);
} else {
// error
alert("Invocation Errors Occured" + invocation.readyState);
}
} else {
dump("currently the application is at " + invocation.readyState);
}
}
</script>
<button type="button" onclick="callOtherDomain()">Test</button>
<div id="textDiv"></div>
@luc99 de oplossing van php4u is de beste maar dat gaat alleen als je php kan gebruiken.Het probleem lijken mij inderdaad de CORS headers.
PHP heeft daar geen moeite mee
Ik zoek en zoek, maar het blijft voor mij onduidelijk.
Kan je een voorbeeld geven van hoe dit dient te gebeuren.
<?php
$feedURL = "http://192.168.1.61:8090/now_playing";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $feedURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
$json = curl_exec($ch);
?>
const powerButton = document.getElementById('power');
let apis = {
boseSoundTouch: {
//get user selected recomendation weather
api:"http://192.168.1.61",
port:":8090",
getUrl: (endpoint) => {
return apis.boseSoundTouch.api + apis.boseSoundTouch.port + "/" + endpoint
},
getVolumeUrlBody: (endpoint, value) => {
return "<" + endpoint + ">" + value + "</"+endpoint+">"
},
getSourceUrlBody:(source, sourceAccount) => {
return "<ContentItem source=" + source + " sourceAccount=" + sourceAccount + "></ContentItem>"
},
getBluetoothUrlBody:(source) => {
return "<ContentItem source=" + source + "></ContentItem>"
},
getKeyUrlBody:(state, sender, key) => {
return "<key state=" + state + " sender=" + sender + ">" + key + "</key>"
}
}
};
const apiCall = (endpoint, bodyOfRequest) => {
console.log("Endpoint : " + endpoint + "\n" + "Body of Request : " + bodyOfRequest)
fetch(apis.boseSoundTouch.getUrl(endpoint), {method: 'post', body: bodyOfRequest})
.then(response => response.text())
.then(str => (new window.DOMParser()).parseFromString(str, "text/xml"))
.then(data => console.log(data))
}
const power = () => {
console.log('power');
var state = "press"
var sender = "Gabbo"
var key = "POWER"
var bodyOfRequest = apis.boseSoundTouch.getKeyUrlBody(state,sender,key)
apiCall('key', bodyOfRequest)
};
powerButton.addEventListener('click', function() {
power;
alert ('hello');
});
const power = () => {
console.log('power');
var state = "press"
var sender = "Gabbo"
var key = "POWER"
var bodyOfRequest = apis.boseSoundTouch.getKeyUrlBody(state,sender,key)
apiCall('key', bodyOfRequest)
};
powerButton.addEventListener('click', function() {
power,
$.ajax({
type: "GET",
url: "/php/now_playing.php",
data: {
},
success: function (data) {
alert(data);
}
});
});
$.ajax({
type: "GET",
url: "/bose/php/now_playing.php",
data: {
},
success: function (data) {
location.reload();
}
});
alert('<?php echo $resultaat ?');
We gebruiken essentiële cookies om deze site te laten werken, en optionele cookies om de ervaring te verbeteren.