|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Hi Guys
I have this code in my page, but I keep getting Access Is Denied Javascript error when i try to load the page in different sub-domains in our server network(sub1.mydomain.com, sub2.mydomain.com), but works fine on the main domain (www.mydomain.com) Code:
<script>
function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("GET","http://www.mydomain.com/ajax/time.asp",true);
xmlHttp.send(null);
}
</script>
The error is pointing to the line: Code:
xmlHttp.open("GET","http://www.mydomain.com/ajax/time.asp",true);
Any idea why this would be? Thanks in advance for any help. Alex Additional Info: I just setup a subdomain to point to exactly the same directory as the main domain and the script doesn't work on this new subdomain either. Any Ideas. Also, Running the script in my local machine IIS (localhost/script.asp) is runs fine. I am at a loss on this one. ![]() |
|
#2
|
|||
|
|||
|
Cross domain requests are not allowed to XMLHttpRequest; yes, even for a subdomain.
One workaround is to use a proxy; this article on Yahoo! explains and details how to do this. Another method is to use an iframe. Here's another article I ran across. And another (PDF) HTH! |
|
#3
|
||||
|
||||
|
thanks lnxgeek,
I didn't relalise cross-domain security was so tight to stop subdomain, but I guess I'll try something different with my problem and see what other problems I can make for myself ![]() |
|
#4
|
|||
|
|||
|
cross domain security is so tight that if you are on http://sitename.com and you call http://www.sitename.com it will deny access!
|
|
#5
|
|||
|
|||
|
I ran into this same issue, where people access the page the script is being called from different ways. There are four different ways that a person can access the main page:
Code:
http://subdomain.domain.com https://subdomain.domain.com http://subdomin https://subdomain They can go straight to the subdomain, because it is in the DNS of our internal network that way. To alleviate this issue, I was trying to write a script, that would loop through the different ones, catching the error and then trying the next one, until it found one that worked or ran out of options. My script looked something like this: Code:
var x = 0;
var urlArray=new Array();
urlArray[0]="http://subdomain.domain.com";
urlArray[1]="https://subdomain.domain.com";
urlArray[2]="http://subdomain";
urlArray[3]="https://subdomain";
xmlHttp.onreadystatechange=stateChanged;
while(x<4){
try {
xmlHttp.open("GET",urlArray[x],true);
x=5;
} catch(err) {
x++;
alert(x);
}
}
The issue i'm having is that after the first catch, it quits running the script. |
|
#6
|
|||
|
|||
|
This might not be of much help but just felt like sharing this ... You can enable cross-domain on IE by going into Internet Options -> Security Settings ->Custom level and enabling "Access data sources across domains".
Regards, Anu Shahdadpuri |
|
#7
|
||||
|
||||
|
If you know your clients, ergo this is an intranet application, you could also set as requirement Firefox 3 or IE8, they support cross domain xhr.
|
|
#8
|
|||
|
|||
|
That sounds like a really, really bad idea. Browsers cannot cross-domains (normally) but your server side scripts can, so why not handle it that way?
__________________
[PHP] | [Perl] | [Python] | [Java] | [Javascript] | [XML] | [ANSI C] | [C++] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS] |
|
#9
|
|||
|
|||
|
You should not set such restrictions on users in order for them to use your webpage, that is just bad practice. If a solution cannot be figured out to a problem without restricting the user, then the problem should be rethought because something must have gotten missed somewhere.
|
|
#10
|
||||
|
||||
|
Quote:
Using a server-side script as a proxy is extra overhead, but it is much better than restricting users to a particular browser.
__________________
Spreading knowledge, one newbie at a time. Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around. Check out my blog. |
|
#11
|
|||
|
|||
|
I probably should have told what my solution was, just didn't realize I never posted it. What I ended up doing was, getting the URL of the page being accessed. I used window.location.href and parsed this to give me the first part of the URL. Once I had the first part of the url, I then appended it to the ajax URL so that I did not have any cross domain issues. This was the best solution I could come up with for my problem. The users didn't have any restrictions set on them (well, except the use of javascript, but if they aren't using that, then they most likely aren't able to use a lot of sites out there).
|
|
#12
|
|||
|
|||
|
Quote:
Plus we're talking about an intranet, so the bandwidth isn't going to be an issue. |
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > AJAX Problem - Access is Denied |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|