Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem fetching remote xml file

Status
Not open for further replies.

rammi07

Programmer
Aug 1, 2006
20
NL
Hi all i am using the follwoing code to display a feed but when run i get the following error:access is denied

xmlobj.open('GET',doc,true); ===>access is denied. error line 34

If i download the same xml file manually and place it in same folder as script then i do not get error. could any one tell me how to fix this problem.Thanks


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html>
<head>
<title>READING XML FILES WITH AJAX</title>
<script type="text/javascript">
// initialize XMLHttpRequest object
var xmlobj=null;
var data=new Array();
// send http request
function sendRequest(doc){
    // check for existing requests
    if(xmlobj!=null&&xmlobj.readyState!=0&&xmlobj.readyState!=4){
        xmlobj.abort();
    }
    try{
        // instantiate object for Mozilla, Nestcape, etc.
        xmlobj=new XMLHttpRequest();
    }
    catch(e){
        try{
            // instantiate object for Internet Explorer
            xmlobj=new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch(e){
            // Ajax is not supported by the browser
            xmlobj=null;
            return false;
        }
    }
    // assign state handler
    xmlobj.onreadystatechange=stateChecker;
    // open socket connection
    [b]xmlobj.open('GET',doc,true); ===>access is denied. error [/b]
    // send GET request
    xmlobj.send(null);
}
// check request status
function stateChecker(){
    // if request is completed
    if(xmlobj.readyState==4){
        // if status == 200 display text file
        if(xmlobj.status==200){
            // create data container
            createDataContainer();
            // read XML data
            data=xmlobj.responseXML.getElementsByTagName
('song');
 // display XML data
            displayData();
        }
        else{
            alert('Failed to get response :'+ xmlobj.statusText);
        }
    }
}
// create data container
function createDataContainer(){
    var div=document.getElementById('container');
    if(div){return};
    var div=document.createElement('div');
    div.setAttribute('id','container');
    document.getElementsByTagName('body')[0].appendChild(div);
}
// display data at a given time interval
function displayData(){
    // reset data container
    document.getElementById('container').innerHTML='';
    var ul=document.createElement('ul');
    for(var i=0;i<data.length;i++){
        // create links
        var li=document.createElement('li');
        var a=document.createElement('a');
        // assign 'href' attribute
        a.setAttribute('href',data[i].getElementsByTagName('artist')
[0].firstChild.nodeValue);
        // add link labels
        a.appendChild(document.createTextNode(data
[i].getElementsByTagName('name')[0].firstChild.nodeValue));
        li.appendChild(a);
        ul.appendChild(li);
    }
    document.getElementById('container').appendChild(ul);
    // update headlines each 1 hour
    setTimeout("sendRequest('[URL unfurl="true"]http://www.radiojavan.com/rss.php?xml=true&count=10')",25*1000);[/URL]
}
// execute program when page is loaded
window.onload=function(){
    // check if browser is DOM compatible
    if(document.getElementById&&document.
getElementsByTagName&&document.createElement){
        // load XML file
        sendRequest('[URL unfurl="true"]http://www.radiojavan.com/rss.php?xml=true&count=10');[/URL]
    }
}
</script>
<style type="text/css">
#container {
    background: #eee;
    padding: 5px;
    border: 1px solid #000;
}
li {
    margin-top: 5px;
}
a:link,a:visited {
    font: bold 11px Tahoma, Arial, Helvetica, sans-serif;
    color: #00f;
}
a:hover {
    color: #f00;
}
</style>
</head>
<body>
</body>
</html>
 
I have a feeling the problem is with permission settings on your server, cause I copy/pasted your code, and I got no errors at all.

[small]"There's an old saying in Tennessee — I know it's in Texas, probably in Tennessee — that says, fool me once, shame on — shame on you. Fool me — you can't get fooled again." - George W. Bush[/small]
<.
 
monksnake thank u for u reply. i tried it both on localhost and one of free php hosting website and both give me same access denied error. could u tell me how to change the permissions and what shold be the permission setting ?

i am using IE 7. do u think that is the problem. I want a solution that all user be able to run the page.
 
Ok I has your program ran in IE6 (which I use) AND IE7. It was IE7 that gave me the Access is denied error.

[small]"There's an old saying in Tennessee — I know it's in Texas, probably in Tennessee — that says, fool me once, shame on — shame on you. Fool me — you can't get fooled again." - George W. Bush[/small]
<.
 
monksnake so could u tell me what should i do to fix this problem?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top