XMLHttpRequest open () failed

I have a problem with the xhr open () method. My code is:

var xmlhttp=false;

if(!xmlhttp)
    try
    { 
        xmlhttp=new XMLHttpRequest(); 
    }
    catch(e)
    {
        xmlhttp=false;
    }

function returnPage(url)
{
    if(!xmlhttp)
        return alert("Your browser doesn't seem to support XMLHttpRequests.");

    xmlhttp.open("GET",url,true);
    xmlhttp.onreadystatechange=function()
    {
        if(xmlhttp.readyState!=4) return;
        if(!xmlhttp.status||xmlhttp.status==200)
            alert(xmlhttp.responseText);
        else
            alert("Request failed!");
    }; //onreadystatechange

    xmlhttp.send(null);
}

Call:

<a href='#' onclick="returnPage('http://www.something.com'); return false;">Link 1</a></p>

I am using IE8 (because I am building a web fragment) and I received the "Access denied" error message. I found on the Internet that the problem is that XHR does not work in different domains, but I used the code from the Firefox add-on, which works fine. Both this additional code and the “my” code (the same) invoke the same page. How does this add-on have access, but my code does not work?

+3
source share
1 answer

Is the domain you are calling AJAX in the same domain as your site? You cannot send requests to other domains.

EDIT

Firefox ( ). .

+6

Source: https://habr.com/ru/post/1742678/


All Articles