Jump to content

Show output of PHP script in a div?


lynxus

Recommended Posts

Hi guys.

I have a script on a webserver , lets say 10.0.0.2

 

my main page is on 10.0.0.1/index.html

 

Does anyone know how i can get the data from the script on the html page?

 

Im assuming maybe javascript on the html page could go look for the output of output.php ?

 

I hope this makes sense?

 

Thanks

G

Link to comment
https://forums.phpfreaks.com/topic/134667-show-output-of-php-script-in-a-div/
Share on other sites

You're making easy things difficult...

 

Yes you can use javascript to load output of php script into div - this technology is called AJAX

 

You can also rename your index.html to index.php and put your php code into it. That's easier but might not be exactly what you're looking for (hard to say without more information)

You're making easy things difficult...

 

Yes you can use javascript to load output of php script into div - this technology is called AJAX

 

You can also rename your index.html to index.php and put your php code into it. That's easier but might not be exactly what you're looking for (hard to say without more information)

 

 

It's different hosts, so AJAX won't work ;p.

OK ive managed this, but it doesnt work when i run this script on another machine other than the one with the PHP script on..

Any ideas how i can get round this ? This has been driving me mad for about 3 months now and really starting to bugger up my plans.

 

Essentially what im trying to do is have a user put some small code on their site with someting like ID=1 in their code.

When a user visits it will goto my php script on another server. the script will then output some html that gets placed in the div on the end users machine.

 

For the life of me i cant get this working on any other machine than the one that the php script is actually on.

 

<html>
<body onload="ajaxContentUpper();">

<script language="javascript" type="text/javascript">
<!-- 
function ajaxContentUpper() {
  var ajaxRequest;
  try {
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
  } catch (e) {
    // Internet Explorer Browsers
    try {
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        // Something went wrong
        alert("Your browser broke!");
        return false;
      }
    }
  }
  // Create a function that will receive data sent from the server
  ajaxRequest.onreadystatechange = function() {
    if(ajaxRequest.readyState == 4) {
      var ajaxDisplay = document.getElementById('TestContent');
      var result = ajaxRequest.responseText;
      if (result == 'expired') {
        window.location = '/';
      } else {
        ajaxDisplay.innerHTML = result;
        reSizeLeftRight();
      }
    }
  }
  ajaxRequest.open("GET", "http://212.125.94.168/ajax/gimme.php", true);
  ajaxRequest.send(null);
}


//-->
</script>

<div id = "TestContent">
</div>

</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.