...

View Full Version : Using jQuery across different servers



Sim
02-22-2011, 06:22 PM
My code works fine on my own server, but I want people to place a piece of JS on there site which will then call the php file on my server and display different results. I keep getting "Access Denied" is there any sort of work-a-round for this?

VIPStephan
02-22-2011, 06:48 PM
JavaScript does not allow access to files on different hosts; this is called the same origin policy (http://en.wikipedia.org/wiki/Same_origin_policy). The only way would be to put an iframe (dynamically with JS) and load your content there. That’s how Facebook and the like are doing it anyway.

Sim
02-22-2011, 06:56 PM
Would json be able to do it?

venegal
02-22-2011, 07:23 PM
You probably mean JSONP.

Yes, you can do it with JSONP.

Sim
02-22-2011, 10:17 PM
Could you point me a tutorial for JSONP??

venegal
02-22-2011, 11:56 PM
This here seems to cover all you have to know:
http://www.ibm.com/developerworks/library/wa-aj-jsonp1/

It uses jQuery, but that's probably not a bad thing.

oesxyl
02-23-2011, 01:41 AM
This here seems to cover all you have to know:
http://www.ibm.com/developerworks/library/wa-aj-jsonp1/

It uses jQuery, but that's probably not a bad thing.

maybe this will help too:

http://www.w3.org/TR/cors/

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum