The following code doesn't replace the ? with data when running using call back function. But works when not using call back function. I would prefer not to use synchronize mode to avoid looking stalled when waiting. Can you help?
URL:
<?php
function usIndex($str)
{
$row = explode(",",trim($str));
echo '<TABLE border="1">';
echo '<TR>';
echo '<TH>Symbol</TH><TH>High</TH><TH>Current</TH><TH>Potential</TH>';
echo '</TR>';
$ratio = 0;
$dr = 0;
foreach ($row as $rv) {
// $rv = historicalShort($rv);
$rv = '?,?,?,?';
echo '<TR>';
$col = explode(',', $rv);
if ($col[3] > $ratio) {
$symbol = $col[0];
$highest = $col[1];
$current = $col[2];
$ratio = $col[3];
}
$cc = 0;
foreach ($col as $cv) {
echo "<TD><DIV id='x$dr$cc'>$cv</DIV></TD>";
$cc++;
}
echo '</TR>'."\n";
$dr++;
}
echo '</TABLE>';
}
?>
<HTML>
<HEAD>
<script type="text/javascript">
function loadXMLDoc(url,r)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET",url);
XMLHttp.onreadystatechange = function() {
if (XMLHttp.readyState == 4) {
var data = xmlhttp.responseText.split(",");
for (var c=0;c<4;c++) {
var id = "x" + r + c;
document.getElementById(id).innerHTML=data[c];
}
}
}
xmlhttp.send(null);
}
</script>
</HEAD>
<BODY>
<?php
if (isset($_GET['index'])) {
$index = $_GET['index'].'.txt';
$str = file_get_contents($index);
$str = str_replace("\n", ",", $str);
usIndex($str);
}
?>
<a href="?index=dji" target="dji">Dow Jones Industrial</a>
<a href="?index=sp100" target="sp100">S & P 100</a>
<a href="?index=sp500" target="sp500">S & P 500</a>
<form action="?" target="stock">
<input type="text" name="stock" value="C">
<input type="submit" value="Submit">
</form>
<script type="text/javascript">
var stocks = "<?php echo $str;?>";
var sym = stocks.split(",");
for (i=0; i<sym.length; i++) {
url = "getstock.php?stock=" + sym;
loadXMLDoc(url,i);
}
</script>
</BODY>
</HTML>
URL:
<?php
function usIndex($str)
{
$row = explode(",",trim($str));
echo '<TABLE border="1">';
echo '<TR>';
echo '<TH>Symbol</TH><TH>High</TH><TH>Current</TH><TH>Potential</TH>';
echo '</TR>';
$ratio = 0;
$dr = 0;
foreach ($row as $rv) {
// $rv = historicalShort($rv);
$rv = '?,?,?,?';
echo '<TR>';
$col = explode(',', $rv);
if ($col[3] > $ratio) {
$symbol = $col[0];
$highest = $col[1];
$current = $col[2];
$ratio = $col[3];
}
$cc = 0;
foreach ($col as $cv) {
echo "<TD><DIV id='x$dr$cc'>$cv</DIV></TD>";
$cc++;
}
echo '</TR>'."\n";
$dr++;
}
echo '</TABLE>';
}
?>
<HTML>
<HEAD>
<script type="text/javascript">
function loadXMLDoc(url,r)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET",url);
XMLHttp.onreadystatechange = function() {
if (XMLHttp.readyState == 4) {
var data = xmlhttp.responseText.split(",");
for (var c=0;c<4;c++) {
var id = "x" + r + c;
document.getElementById(id).innerHTML=data[c];
}
}
}
xmlhttp.send(null);
}
</script>
</HEAD>
<BODY>
<?php
if (isset($_GET['index'])) {
$index = $_GET['index'].'.txt';
$str = file_get_contents($index);
$str = str_replace("\n", ",", $str);
usIndex($str);
}
?>
<a href="?index=dji" target="dji">Dow Jones Industrial</a>
<a href="?index=sp100" target="sp100">S & P 100</a>
<a href="?index=sp500" target="sp500">S & P 500</a>
<form action="?" target="stock">
<input type="text" name="stock" value="C">
<input type="submit" value="Submit">
</form>
<script type="text/javascript">
var stocks = "<?php echo $str;?>";
var sym = stocks.split(",");
for (i=0; i<sym.length; i++) {
url = "getstock.php?stock=" + sym;
loadXMLDoc(url,i);
}
</script>
</BODY>
</HTML>