Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Header and Access-Control_Allow_Origin Error
    primarykey
    data
    text
    <p>I have two domains, leobee.com and txtease.com. I'd like to load a xml script from leobee.com into a php page on txtease.com. I was able to get the information to create the script below by researching stackoverflow site, However, I did not see how to fix this issue. </p> <p>I've added php headers to the requesting script, and I'm getting "Origin is not allowed by Access-Control-Allow-Origin" error. </p> <p>Can you look at my script and let me know where I went wrong? The test script is live at: <a href="http://txtease.com/crossdomain/scripts/example.html" rel="nofollow">http://txtease.com/crossdomain/scripts/example.html</a></p> <p>in the chrome/ or firebug console use this: createCORSRequest('GET', '<a href="http://www.leobee.com/crossdomain/data/data.xml" rel="nofollow">http://www.leobee.com/crossdomain/data/data.xml</a>');</p> <p>PHP script:</p> <pre><code> &lt;?php echo "PHP Running"; header('Access-Control-Allow-Origin: http://www.leobee.com'); ?&gt; &lt;script&gt; var xhr = new window.XMLHttpRequest(); var string; function createCORSRequest(method, url) { if ("withCredentials" in xhr) { // Check if the XMLHttpRequest object has a "withCredentials" property. // "withCredentials" only exists on XMLHTTPRequest2 objects. xhr.open(method, url, true); xhr.send(null); string ="with Credentials"; xhr.onerror = function() {console.log('There was an error!')}; xhr.onreadystatechange = callbackFunction(string); } else if (typeof XDomainRequest != "undefined") { xhr = new XDomainRequest(); xhr.open(method, url); xhr.send(null); string ="x domain request"; xhr.onreadystatechange = callbackFunction(string); } else if(!"withCredentials" in xhr){ xhr.open(method, url, true); xhr.send(null); string ="with no Credentials"; xhr.onreadystatechange = callbackFunction(string); }else { // Otherwise, CORS is not supported by the browser. alert("cross domain not supported"); xhr = null; } return xhr; } function callbackFunction(string){ console.log("Responding function: "+string); if (xhr.readyState == 4){ var responseText = xhr.responseXML; console.log("xml string is: "+responseText); if (xhr.responseXML ===null){ responseText=xhr.responseText; console.log("html string is: "+responseText); } } } &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload