new to HTML and AJAX programming so here goes:
I've created a website that fills a table with content from an external txt file (content.txt). The text file is located on a Windows 2003 webserver and is located in the C:\Inetpub\wwwroot folder (so its accessible by http://servername:port/content.txt). The current AJAX code I have for my website is this:
function content(file)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
开发者_开发技巧 populate();
}
}
var right_now = new Date();
xmlhttp.open("POST",file + "?" + right_now.getTime(),true);
xmlhttp.send();
}
And then in the HTML body I have:
<body id="body" onload="javascript:content('http://servername:port/content.txt')">
Now this code works and the webpage loads fine if I run it from a computer on the same network. But if I put it on the server and make it a "live" website (using IIS), and then try and access the website from another computer on the network, IE chucks an error saying "Access is denied" pointing to the xmlhttp.open line.
Now I've read that AJAX doesn't work over different domains, but surely in this situation they are on the same domain? Or maybe my idea of domains is completely wrong. Hopefully you guys can help a newbie out. Cheers.
it seems like it's a port issue. check out this [similar] issue to what you are experiencing.
to quote that other post:
For two documents to be considered to have the same origin, the protocol (http/https), the domain and the port (the default 80 or :xx) have to be indentical. So no, you cannot use xhr against a different port.
精彩评论