Created
October 21, 2013 16:29
-
-
Save wupsbr/7086748 to your computer and use it in GitHub Desktop.
Exemplo de como fazer uma chamada AJAX (XMLHttpRequest) no Firefox OS em um domínio diferente da aplicação, evitando o erro de Cross-Origin. Aplicação completa em https://github.com/robnyman/Firefox-OS-Boilerplate-App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var xhr = new XMLHttpRequest({mozSystem: true}); | |
xhr.open("GET", "http://robnyman.github.com/Firefox-OS-Boilerplate-App/README.md", true); | |
xhr.onreadystatechange = function () | |
{ | |
if (xhr.status === 200 && xhr.readyState === 4) | |
{ | |
crossDomainXHRDisplay.innerHTML = "<h4>Result from Cross-domain XHR</h4>" + xhr.response; | |
crossDomainXHRDisplay.style.display = "block"; | |
} | |
} | |
xhr.onerror = function () | |
{ | |
crossDomainXHRDisplay.innerHTML = "<h4>Result from Cross-domain XHR</h4><p>Cross-domain XHR failed</p>"; | |
crossDomainXHRDisplay.style.display = "block"; | |
}; | |
xhr.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment