i have a HTML page with an ajax request that is working well on firefox, but safari doesn't do anything. when i am debugging, i see that readystate is undefined and status is "". Does anyone sees why it doesn't work on safari?
Javascript Code:
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML =
this.responseText;
}
};
xhttp.open("GET", "pegSolitaireSettings.html", true);
xhttp.send();
}
function reloadGame() {
location.reload();
}
</script>
HTML Code:
<div id="demo">
<button type="button" onclick="loadDoc()">Settings</button>
<div class="center-div">...</div>
</div>
Firefox is fixing your error for you while Safari is not.
You are attempting to request a relative URL: "pegSolitaireSettings.html"
Change that to: "http://HOSTNAME/pegSolitaireSettings.html"
or "//HOSTNAME/pegSolitaireSettings.html"
and it will work fine.
Where HOSTNAME is the domain name for the host.
This is what i actually have (simplified) and i can access http://www.pegsolitaire.com/pegSolitaireSettings.html
in my browser, so the vhost should not be the problem
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="CSS/styles.css" type="text/css"> <script> function loadDoc() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("demo").innerHTML = this.responseText; } }; xhttp.open("GET", "http://www.pegsolitaire.com/pegSolitaireSettings.html", true); xhttp.send(); } function reloadGame() { location.reload(); } </script> </head> <body> <div id="demo"> <button type="button" onclick="loadDoc()">Settings</button> <div id="gameInfo" align="center"> <br> <div class="values" id="totalTime"></div> </div> </div> </body> </html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.