PHP echo calling AJAX function outside of HTML <script> file
Posted: Wed Sep 30, 2009 3:53 pm
I have three files, for the sake of simplifying the problem:
1. HTML, with javascript include statement in the header
2. AJAX controller file which points method calls from (1) to the correct PHP file in (3)
3. PHP file that does string manipulations, graph rendering, etc.
So here's the scenario. I have a simple HTML page that has an input form and submit button. The Submit calls a "render()" JS method which is read by the AJAX controller and calls a PHP page that renders and echos a graph back to the HTML page.
HTML
AJAX
PHP
As you can see, once the graph is drawn, I want to put a link under it that the user can click to redraw the graph without refreshing the page (AJAX). Problem is, the PHP file does not have the .JS include (and shouldn't, won't) but the echo isn't giving me a link that calls the function correctly. Perhaps I shouldn't use <a href=...>? Is there another way?
Thanks!
I've created a duplicate entry in the Javascript subforum since this may or may not deal with both languages. Once an answer solves my question or points me in the right direction, I shall delete the other. Thanks for understanding.
1. HTML, with javascript include statement in the header
2. AJAX controller file which points method calls from (1) to the correct PHP file in (3)
3. PHP file that does string manipulations, graph rendering, etc.
So here's the scenario. I have a simple HTML page that has an input form and submit button. The Submit calls a "render()" JS method which is read by the AJAX controller and calls a PHP page that renders and echos a graph back to the HTML page.
HTML
Code: Select all
<html>
<head><script type="text/javascript" src="ajax_controller.js"></script></head>
<body>
<form>
...
<input type='button' class="submitButton" id="submitButton" onClick='render(...)' value='Submit'/>
</form>
...
Code: Select all
var xmlhttp;
function render(...)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="graph.php"; // get the result and display
url=url+"?...="+X; // the team selection
url=url+"&...="+Y; // the stat selection
xmlhttp.onreadystatechange=getRender;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function getRender()
{
if (xmlhttp.readyState==4)
{
document.getElementById("...").innerHTML=xmlhttp.responseText;
}
}
Code: Select all
<?php>
....
echo $graph (...)
....
echo "<a href='#' onClick=\"render({$Y}+1, {$X});return false;\">Re-render</a>"; // TODO: Echo back new link that re-calls using AJAX
</?>
Thanks!
I've created a duplicate entry in the Javascript subforum since this may or may not deal with both languages. Once an answer solves my question or points me in the right direction, I shall delete the other. Thanks for understanding.