Perché il seguente codice Based on Mozilla example non funziona? Provato con Firefox 3.5.7 & Chrome.XMLHttpRequest per ottenere risposta HTTP dall'host remoto
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
</body>
<script>
var req = new XMLHttpRequest();
req.open('GET', 'http://www.mozilla.org/', false);
req.send();
if(req.status == 200) {
alert(req.responseText);
}
</script>
</html>
prega che il browser sta tirando il codice HTML dal disco locale (file: /// C: /Users/Maxim%20Veksler/Desktop/XMLHTTP.html)
Su Firefox dà il seguente errore :
uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: file:///C:/Users/Maxim%20Veksler/Desktop/XMLHTTP.html :: <TOP_LEVEL> :: line 10" data: no]
Cosa sto facendo male? Voglio inviare una richiesta all'host remoto e avvisare il risultato (in seguito aggiunto in un div).
OK, così come fa l'integrazione JavaScript di Google Analytics funziona codice? –
@Maxim: potresti voler controllare questo post SO: ** In che modo google analytics raccoglie i suoi dati? **: http://stackoverflow.com/questions/892049/how-does-google-analytics-collect-its -dati –