Support Spidean

Do you like our FREE downloads? How about the FREE support for the FREE downloads? Please help us out and donate any amount! It's fast and easy through PayPal.

Spidean Forums

Board Index > PHP > How do I use php code from a different domain?


 < Last Thread   Next Thread >New Topic  Post Reply
Author: Subject: How do I use php code from a different domain?

Newbie





Posts: 3
Registered: 1/25/2010
Status: Offline

  posted on 2/3/2010 at 10:58 AM
HI

Here's what I'm trying to do: I have a php page I created on one domain, that stores information in a database. Next, I have another web page (This page is html NOT php) on a Different domain that I call this php page using Javascript, and would like to return a variable from the php page. How is this possible? I know it is, so don't say that it isn't!

 

____________________
fbh

 
Reply With Quote

Administrator




Posts: 4608
Registered: 10/7/2002
Status: Online

  posted on 2/3/2010 at 04:29 PM
In general you would do it like this:

Your php page:

$id = $_GET['id'];
//do some database query and fetch the array
//json_encode the array and echo
echo json_encode(array('id'=>$id, 'name'=>'test', 'descr'=>'test array from db'));

Your HTML page:

<html>
<head>
<script type="text/javascript">
xhttp = new XMLHttpRequest();
xhttp.open("GET", "http://example.com/script.php?id=1", false);
xhttp.send("");
response = xhttp.responseText;
var myArray = eval('(' + response + ')');

document.writeln(myArray.id);
document.writeln(myArray.name);
</script>
</head>
<body>
</body>
</html>

 
Reply With Quote
New Topic    Post Reply


Main Menu

Get AutoTheme

Featured Item

Poll

How do you like the new look?

[ Results | Polls ]

Votes: 175

Powered by the AutoTheme HTML Theme System
Page created in 0.091029 Seconds