It sounds like you are trying to simply set the contents of an HTML element to the result of executing a PHP script. Here is a sample PHP script that will just print an HTML link depending on what parameter you pass it in the 'foo' parameter.
<?
// Get the parameter "foo" from the URL string.
$action = $_GET['foo'];
// Return a different link depending on what 'foo' is.
switch ($action) {
case 'a':
print('<a href="Link.php?action=Delete">Delete</a>');
break;
case 'b':
print('<a href="Link.php?actiom=Edit">Edit</a>');
break;
default:
print('<a href="Link.php?action=New">New</a>');
break;
}
?>
Now you need to load that PHP script from inside your HTML file using Javascript (jQuery). Here is a simple page demonstrating that.
<html>
<head>
<title>Demo Page</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(function() {
$.get('ajax.php?foo=a', function(data) {
$('#result').html('Received response: ' + data);
});
});
</script>
</head>
<body>
<!-- This div will contain a link to the "Delete" -->
<div id="result"/>
</body>
</html>
Some things to remember:
- This demo assumes the "ajax.php" and "demo.html" files are in the same directory.
- It is also assumed you have the jQuery Javascript file located in a file called "jquery.js" in a directory called "js".
- You need to run this example from a live web server. In other words, this will not work if you put these files on your desktop and open "demo.html" in a web browser. There are two reasons for this. Security restrictions in modern browsers often times prevent AJAX calls from local files. Also, the PHP page will not run, rendering the whole exercise useless.
Here is the directory structure you should have, assuming /www/data is the root directory of your web server's files:
- /www/data/demo.html
- /www/data/ajax.php
- /www/data/js/jquery.js