Click here to Skip to main content
16,016,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","http://xml.altinkaynak.com.tr/altinkaynak.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
...

I am trying to access xml file of this page http://xml.altinkaynak.com.tr/altinkaynak.xml. When I did this operation on my pc I can access and I can display the xml values which I want. But when I upload my works on my web site it doesn't work on internet so xml values aren't displayed on the screen. How can I solve this problem? Can anyone help me?
Posted
Updated 11-Jan-11 18:07pm
v3
Comments
Sandeep Mewara 12-Jan-11 3:53am    
What issue/error do you face then?
egultekinoglu 12-Jan-11 4:46am    
There isn't any error that i face, just it works but when i upload it to my web site the xml datas are not display
Manfred Rudolf Bihy 13-Jan-11 7:50am    
Can you leave a link here to your webserver where the page is hosted?

1 solution

If xml.altinkaynak.com.tr is not where your webservers is at you have do some tricks. If a client ajax request tries to access a website on a different domain this is blocked by the browser. There are some ways to work around this see here: http://msdn.microsoft.com/en-us/library/dd573303(v=vs.85).aspx[^]

If your webserver is on xml.altinkaynak.com.tr you can also try this code:
XML
<html>
<body>
<textarea id="showXML" rows="35" cols="80" value="This is where the XML will go">
</textarea>
<input id="submitter" type="button" name="getXML" value="Go get it!" onclick="getXML();">
<script type="text/javascript">
function getXML()
{
    var submitter = document.getElementById("submitter");
    submitter.disabled = true;
    var xmlHttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlHttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    //debugger;
    xmlHttp.open("GET","http://xml.altinkaynak.com.tr/altinkaynak.xml",false);
    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4)
        {
            var xml = xmlHttp.responseText;
            document.getElementById("showXML").value = xml;
            submitter.disabled = false;
        }
    }
    xmlHttp.send();
};
</script>
</body>
</html>



Best Regards,
Manfred
 
Share this answer
 
v5
Comments
egultekinoglu 13-Jan-11 5:41am    
firstly thanks for your concern, your code block has worked on my pc but i uploaded it to my web site it doesn't work again.
xmlHttp.open("GET","http://xml.altinkaynak.com.tr/altinkaynak.xml",false); if i change there like:
xmlHttp.open("GET","altinkaynak.xml",false); and i add an altinkaynak.xml file on my web site it works proper. I didn't understand that problem.
Manfred Rudolf Bihy 13-Jan-11 7:47am    
Please read my answer carefully. If http://xml.altinkaynak.com.tr is NOT your webserver, webpages served from your webserver CANNOT easily access another host via AJAX. Even if the former is also your host the problem persists if your webpages are served from a different domain than the XML file, this has to do with cross domain access. Also study the site I linked to. If you still have questions just leave a comment.
egultekinoglu 13-Jan-11 8:06am    
Sorry I am goning to work on your link after my studies finished i may ask for your advise.
Best Regards,
Erman Gultekinoglu
Manfred Rudolf Bihy 13-Jan-11 15:41pm    
If you have trouble understanding what I wrote, just leave a comment and I'll try to do better.
Happy coding!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900