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? > Post Reply


Post Reply
Icon:
Message:



[More smilies...]
Bold   Italic   Underline   Code   Email   Quote   Url   Image   
Rights

HTML is Off
Smilies are On
BB Code is On
[img] Code is On

Disable smileys?
Use signature?
Turn BBCode off?
Receive email notification of new replies?

Topic Review


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>




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!



Main Menu

Get AutoTheme

Featured Item

Poll

How do you like the new look?

[ Results | Polls ]

Votes: 180

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