How to access different domain data using Java script
- by shoaibmohammed
Hello there,
Here is the issue. Suppose there is a DOMAIN A which is going to be the server containing a PHP Script file. The data from Domain A is to be accessed by a Client at DOMAIN B.
I know it cannot be accessed directly using JavaScript. So what I did is, in Domain A I created a a JavaScript file as front-end for the PHP Script which AJAXes the PHP and returns the data. But unfortunately it din't work
I came across an example having PHP as a Middle Man in the client side. But I donot want to keep any server side PHP code as a middle man in the client side. I just want to give out the Javascript to the client domain.
http://stackoverflow.com/questions/578095/how-to-get-data-with-javascript-from-another-server
DOMAIN A
PHP - data.php
<?php echo "Server returns data"; ?>
JS - example.js
Does the Ajax to the PHP
function getData()
{
//assume ajax is done for data.php and data is retrieved, now return the data
return ajaxed_data;
}
Domain B
JS
Client includes the example.js file from Domain A in his HTML
<script type="text/javascript" src="http://www.DomainA.com/example.js"></script>
<script type="text/javascript">
alert(getData());
</script>
I hope I have made myself understandable ! Can this be established ? Its something like Google friend connect, what I mean is, just provide JavaScript to the client and thats it. Every thing carried out in server side
Thankx for providing this forum