JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 14th, 2007, 09:57 PM
alexk13's Avatar
alexk13 alexk13 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Sydney, Australia
Posts: 50 alexk13 User rank is Corporal (100 - 500 Reputation Level)alexk13 User rank is Corporal (100 - 500 Reputation Level)alexk13 User rank is Corporal (100 - 500 Reputation Level)alexk13 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 6 Days 6 h 20 m 12 sec
Reputation Power: 7
Unhappy AJAX Problem - Access is Denied

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.

Reply With Quote
  #2  
Old June 14th, 2007, 10:21 PM
lnxgeek lnxgeek is offline
I AM A GOLDEN GOD
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Apr 2003
Location: Ventura, California
Posts: 5,885 lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 21 h 44 m 44 sec
Reputation Power: 1033
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!

Reply With Quote
  #3  
Old June 14th, 2007, 10:51 PM
alexk13's Avatar
alexk13 alexk13 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Sydney, Australia
Posts: 50 alexk13 User rank is Corporal (100 - 500 Reputation Level)alexk13 User rank is Corporal (100 - 500 Reputation Level)alexk13 User rank is Corporal (100 - 500 Reputation Level)alexk13 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 6 Days 6 h 20 m 12 sec
Reputation Power: 7
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

Reply With Quote
  #4  
Old June 15th, 2007, 03:42 PM
BornInHollywood BornInHollywood is offline
Roobee On Railz Roolz!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 139 BornInHollywood User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 8 h 53 m
Reputation Power: 0
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!

Reply With Quote
  #5  
Old November 8th, 2007, 12:20 PM
shane_jordan shane_jordan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 7 shane_jordan User rank is Lance Corporal (50 - 100 Reputation Level)shane_jordan User rank is Lance Corporal (50 - 100 Reputation Level)shane_jordan User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 59 m 54 sec
Reputation Power: 0
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.

Reply With Quote
  #6  
Old March 10th, 2008, 04:44 AM
anu_spuri anu_spuri is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 1 anu_spuri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 41 sec
Reputation Power: 0
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

Reply With Quote
  #7  
Old March 10th, 2008, 05:24 AM
execute's Avatar
execute execute is offline
CSKA Sofia
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Germany / Bulgaria
Posts: 565 execute User rank is First Lieutenant (10000 - 20000 Reputation Level)execute User rank is First Lieutenant (10000 - 20000 Reputation Level)execute User rank is First Lieutenant (10000 - 20000 Reputation Level)execute User rank is First Lieutenant (10000 - 20000 Reputation Level)execute User rank is First Lieutenant (10000 - 20000 Reputation Level)execute User rank is First Lieutenant (10000 - 20000 Reputation Level)execute User rank is First Lieutenant (10000 - 20000 Reputation Level)execute User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 7 h 36 m 16 sec
Reputation Power: 118
Send a message via ICQ to execute
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.
__________________
Nikola Ivanov
http://weboholic.de

Reply With Quote
  #8  
Old March 10th, 2008, 06:13 AM
Winters Winters is offline
Bad Coder
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,562 Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Weeks 1 Day 4 h 39 m 50 sec
Reputation Power: 1236
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]

Reply With Quote
  #9  
Old March 10th, 2008, 07:05 AM
shane_jordan shane_jordan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 7 shane_jordan User rank is Lance Corporal (50 - 100 Reputation Level)shane_jordan User rank is Lance Corporal (50 - 100 Reputation Level)shane_jordan User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 59 m 54 sec
Reputation Power: 0
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.
Comments on this post
Winters agrees!

Reply With Quote
  #10  
Old March 10th, 2008, 12:54 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 23rd Plane (16000 - 16499 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 16,407 Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level)Kravvitz User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Months 1 Day 14 h 19 m 23 sec
Reputation Power: 1780
Quote:
Originally Posted by PHP-Newb
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?

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.

Reply With Quote
  #11  
Old March 10th, 2008, 01:01 PM
shane_jordan shane_jordan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 7 shane_jordan User rank is Lance Corporal (50 - 100 Reputation Level)shane_jordan User rank is Lance Corporal (50 - 100 Reputation Level)shane_jordan User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 59 m 54 sec
Reputation Power: 0
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).

Reply With Quote
  #12  
Old March 11th, 2008, 02:54 AM
Winters Winters is offline
Bad Coder
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,562 Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level)Winters User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Weeks 1 Day 4 h 39 m 50 sec
Reputation Power: 1236
Quote:
Originally Posted by Kravvitz
Using a server-side script as a proxy is extra overhead, but it is much better than restricting users to a particular browser.


Plus we're talking about an intranet, so the bandwidth isn't going to be an issue.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > AJAX Problem - Access is Denied


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT