0

I have a php script which are able to power on my computers at home using WoL, then check connectivity of the target machine and output a status.

I'm trying to make a nice webpage for that, where I can press a 'power on' link/button, where it then runs the formentioned script and shows the status right next to the 'power on' button.

I have been told to use AJAX, but can't get it to show anything.

My index.php:

<html>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>WOL</title>

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
function doSomething() {
    $.get("status1.php");
    }
</script>

<?php
echo "10.0.0.20 &nbsp;&nbsp;&nbsp; roadrunner &nbsp;&nbsp;&nbsp;";
echo '<a href="#" onclick="doSomething()">power on</a>';
?>

</html>

The stautus1.php ends with

<?php
echo htmlheader(); 
echo htmlcontent(); 
?>

I probably should mention I'm very new with JS and also somewhat new at php.

What am I doing wrong?

1 Answer 1

1

You're not doing anything with the loaded content after you actually load it... Probably the easiest way would be to use the load function because you can specify its container as well as the callback function. For example:

HTML container

<div id="mydiv"></div>

JS

$('#mydiv').load('status1.php');

or with the callback

$('#mydiv').load('status1.php', function() {alert('Loaded!');});
Sign up to request clarification or add additional context in comments.

4 Comments

I can't get that to work either. Let me just be sure I understand it correct: My JS should look like this: <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript"> function doSomething() { $('#mydiv').load('status1.php', function() {alert('Loaded!');}); } </script> I have put <div id="mydiv"></div> into the html container. But when i press 'power on' still nothing happens.
Yes, that's the correct code... See if you get any errors in the Console (Dev Tools in Chrome, for example), and also check what happens when you open the file status1.php directly in browser.
facepalm my jquery.min.js was named wrong on the server. It now displays the output upon pressing the link. Not in the right place, but thats some formatting I need to mess around with :-) I have however run into another problem, which I just realize now is my own fault. The status1.php have a function that refreshes the page if no connection to the target machine is made. It will refresh 10 times before just echoing "FAILED". This makes the whole index fresh. Any way to avoid this?
Well, I guess you need to disable that refreshing thing... Or open another question here, since I don't think I can help you without further details about the new problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.