I have following code (HTTPS AJAX) and in IE 11 this runs well only in debug mode. The problem is that in IE onclick event does not trigger any action. But how to debug it? When I open dev tools, script runs just fine and console.log is empty. I know i have many commented code out, but no console() is there. I removed this already thinking this is the problem. What can be a cause that IE 11 does not accept it?
UPDATE: I tried various things, META tags, cache control, etc, but nothing helped. Only what helped was to add Math.random()
to control caching.
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
does not work
req.setRequestHeader('Cache-Control', 'no-cache');
does not work
Math.random()
works
<?php include "vars.php"; ?>
<script type="text/javascript">
function HandleGPIO(gpin,value) {
document.getElementById(gpin).innerHTML="Working";
document.getElementById(gpin).style.color="blue";
var req = createHttpRequest();
req.open("GET", "https://mysite.xy/gpio/gpioajax.php?gpio=" + gpin + "&value=" + value, false); //false ceka na vyrizeni
req.setRequestHeader("Content-Type", "text/html; charset=windows-1250");
req.send(null);
if(req.responseText == 0){
QueryGPIO(); //Query for updated values
return true;
}
else if(req.responseText == 1){
QueryGPIO(); //Query for updated values
return true;
}
else{
window.alert('Spatny navratovy kod pro AJAX, chyba: ' + req.responseText);
QueryGPIO(); //Query for updated values
return false;
}
}
function QueryGPIO() {
//var arr_inputs = ['5','21','27'];
var arr_inputs = <?php echo '["' . implode('", "', $pins_array_in) . '"]' ?>;
var arr_outputs = <?php echo '["' . implode('", "', $pins_array_out) . '"]' ?>;
//Query Inputs
for (var i = 0; i < arr_inputs.length; i++) {
(function(i) {
//alert(arr_inputs[i]);
var req = createHttpRequest();
req.open("GET", "https://mysite.xy/gpio/gpioajaxquery.php?gpio=" + arr_inputs[i], false); //false ceka na vyrizeni
req.setRequestHeader("Content-Type", "text/html; charset=windows-1250");
req.send(null);
//window.alert(req.responseText);
if(req.responseText == '0'){
document.getElementById(arr_inputs[i]).innerHTML='ON';
document.getElementById(arr_inputs[i]).style.color='green';
//document.getElementById(arr_inputs[i]).addEventListener("click", function() { HandleGPIO(arr_inputs[i], 1); }, false);
//document.getElementById(arr_inputs[i]).setAttribute('onclick','HandleGPIO('+arr_inputs[i]+',1)');
document.getElementById(arr_inputs[i]).onclick = function () { HandleGPIO(arr_inputs[i],1); };
}
else if(req.responseText == '1'){
document.getElementById(arr_inputs[i]).innerHTML='OFF';
document.getElementById(arr_inputs[i]).style.color='red';
//document.getElementById(arr_inputs[i]).setAttribute('onclick','HandleGPIO('+arr_inputs[i]+',0)');
document.getElementById(arr_inputs[i]).onclick = function(debug) {
if(debug === true) {
return [arr_inputs[i], 0];
}
else {
HandleGPIO(arr_inputs[i],0);
}
}
//document.getElementById(arr_inputs[i]).onclick = function() { HandleGPIO(arr_inputs[i],0); };
var temp = document.getElementById(arr_inputs[i]).onclick;
}
else{
window.alert('Spatny navratovy kod pro AJAX');
}
})(i)
}
//var arr_outputs = ['9','12'];
//Query Outputs
for (var i = 0; i < arr_outputs.length; i++) {
(function(i) {
var req = createHttpRequest();
req.open("GET", "https://mysite.xy/gpio/gpioajaxquery.php?gpio=" + arr_outputs[i] + "&r=" + Math.random(), false); //false ceka na vyrizeni
req.setRequestHeader("Content-Type", "text/html; charset=windows-1250");
req.send(null);
//window.alert(req.responseText);
if(req.responseText == '1'){
document.getElementById(arr_outputs[i]).innerHTML='ON';
document.getElementById(arr_outputs[i]).style.color='green';
//document.getElementById(arr_outputs[i]).setAttribute('onclick','HandleGPIO('+arr_outputs[i]+',0)');
//document.getElementById(arr_outputs[i]).addEventListener("click", function() { HandleGPIO(arr_outputs[i], 0); },true);
document.getElementById(arr_outputs[i]).onclick = function() { HandleGPIO(arr_outputs[i],0); };
}
else if(req.responseText == '0'){
document.getElementById(arr_outputs[i]).innerHTML='OFF';
document.getElementById(arr_outputs[i]).style.color='red';
//document.getElementById(arr_outputs[i]).setAttribute('onclick','HandleGPIO('+arr_outputs[i]+',1)');
//document.getElementById(arr_outputs[i]).addEventListener("click", function() { HandleGPIO(arr_outputs[i], 1); },true);
document.getElementById(arr_outputs[i]).onclick = function() { HandleGPIO(arr_outputs[i],1); };
}
else{
window.alert('Spatny navratovy kod pro AJAX');
}
})(i)
}
}
function createHttpRequest() {
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
http_request = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
return http_request;
}
</script>
<a id="27" style="cursor: pointer; color:red;">OFF</a>
<a id="27" style="cursor: pointer; color:red;">ON</a>
<a id="21" style="cursor: pointer; color:red;">OFF</a>
<a id="21" style="cursor: pointer; color:red;">ON</a>
<a id="5" style="cursor: pointer; color:red;">OFF</a>
<a id="5" style="cursor: pointer; color:red;">ON</a>
<a id="9" style="cursor: pointer; color:red;">OFF</a>
<a id="9" style="cursor: pointer; color:red;">ON</a>