Page 1 of 1

Read a page "distance"

Posted: Thu Jun 09, 2011 4:32 am
by fabby
Hi all!
I have a problem when i want to show a banner on a site.
So, on the site A, www.domainA.com/banner.php - is just a banner

On the site B, www.domainB.com, in the right side, i want to show the banner, that is generated on the site A.
I tried this with ajax, and the code that i have to insert on site B is:

Code: Select all

<script type="text/javascript" language="javascript" src="http://www.domainA.com/include/show_banner.js"></script>
<script>show_banner_content();</script>
<div id="msg_err_rapid_login"></div>
where in the file show_banner.js is the function show_banner_content that user ajax to show the banner, and the banner is inserted inside the div <div id="msg_err_rapid_login"></div>

When i tried this on localhost, is ok, but when i put this online, does not want to work!
Can you please tell me why?
Thanks!

Re: Read a page "distance"

Posted: Thu Jun 09, 2011 11:00 am
by Jade
Sounds like a permissions problem.

Re: Read a page "distance"

Posted: Fri Jun 10, 2011 1:59 am
by fabby
what kind of permision? to know what to verify ?

Re: Read a page "distance"

Posted: Fri Jun 10, 2011 4:06 am
by fabby
the file, show_banner.js contain the function:

Code: Select all

function show_banner_content(){
	id_camp_err='msg_err_rapid_login';
	
	xmlHttp=GetXmlHttpObject();
	xmlHttp.open('post','www.domainA.com/banner.php');
	xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange=insertError;
	xmlHttp.send('submit_form=da');
	setTimeout(show_banner_content,"3000");
	}
function insertError() 
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById(id_camp_err).innerHTML=xmlHttp.responseText 
	
	} 
} 
So, the problem i think is because can acces the function show_banner from "distance" or this don't work: xmlHttp.open('post','www.domainA.com/banner.php'); from "distance".

What do you think?
Thanks.

Re: Read a page "distance"

Posted: Fri Jun 10, 2011 10:22 am
by Weirdan
XHR (XML Http Request) is limited to accessing urls only from the domain it runs on (not the domain the script originates from). So script running in the domainB context can't make requests to domainA urls.

You might get better results with JSONP + pointing 'src' attribute of the <script> tag to the remote endpoint. This works with GET requests only though, and that banner.php would likely need to be modified.

Re: Read a page "distance"

Posted: Fri Jun 10, 2011 11:01 am
by Apollo
Weirdan wrote:XHR (XML Http Request) is limited to accessing urls only from the domain it runs on (not the domain the script originates from). So script running in the domainB context can't make requests to domainA urls.
Correct, and therefore a workaround could be to request domainB.com/dummy.php instead of domainA.com/banner.php in your ajax code, and dummy.php is simply a forwarding script that calls (and returns the result of) domainA.com/banner.php with the specified parameters.

Re: Read a page "distance"

Posted: Mon Jun 13, 2011 3:15 pm
by fabby
Thank for the replays.
Do you know any examples to look how to do?