My AJAX requests are not working properly on mobile browsers and iPads, but they work perfectly on desktop computers. I am struggling to figure out what the issue might be.
var xmlhttp;
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == XMLHttpRequest.DONE ){
if(xmlhttp.status == 200){
console.log(xmlhttp.responseText);
}else{
alert("STATUS "+xmlhttp.status);
}
}
}
xmlhttp.open("GET","http://www.mywebsite.co.uk/assets/php/upvote.php?id="+id,true);
xmlhttp.send();
I have also experimented with these variations:
xmlhttp.open("GET","/assets/php/upvote.php?id="+id,true);
and xmlhttp.open("GET","../php/upvote.php?id="+id,true);
All three methods are successful on desktop computers (displaying a success message in the console), but on mobile devices, they result in an alert with "STATUS 0".
I am puzzled as to why everything runs smoothly on desktops, but xmlhttp.status
returns 0
on mobile devices.