Skip to content

Instantly share code, notes, and snippets.

@wupsbr
Created October 21, 2013 16:29
Show Gist options
  • Save wupsbr/7086748 to your computer and use it in GitHub Desktop.
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
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