views:

231

answers:

1

I'm using jQuery to query a database and update a table of bid and ask prices for a currency trading ticker. I'm using $.ajax to send a currency symbol to a php script that queries the database and returns a xml document that javascript parses to make updates to the table. Everything is working in FireFox on both pc/mac and on Safari, but doesn't work in IE. The relevant code...

The jQuery making the ajax call:

var updateDataFunction = function () {
    $.ajax({
     url: "func2.php",
     type: "GET",
     data: "symbol=<?php echo $stock; ?>",
     dataType: "xml",
     success: function (msg) {
      var bid = $('bid',msg).text();
      var ask = $('ask',msg).text();
      var spread = $('spread',msg).text();

      // do some other stuff
     }
});
};

The script uses php to place the stock in the javascript before the javascript is run. The updateDataFunction gets called in a $(document).ready.

The php script

<?php
header("content-type:text/xml;charset=utf-8");

// connect to the database

function GetUpdate($symbol) {

$query = "SELECT * FROM tblSG WHERE strSymbol='$symbol'";
$result = mysql_query($query);

while($row = mysql_fetch_array($result)) {
 $spread= $row['fBid'] - $row['fAsk'];
 $output="<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<exchange>\n";
 $output.="<bid>" . number_format($row['fBid'],4) . "</bid>\n";
 $output.="<ask>" . number_format($row['fAsk'],4) . "</ask>\n";
 $output.="<spread>" . number_format($spread,4) . "</spread>\n";
 $output.="</exchange>";
}

return $output;

}


$symbol = $_GET['symbol'];

echo GetUpdate($symbol);

?>

Using POST instead of GET causes it to fail in FF and Safari as well. Any ideas on a solution to this?

+1  A: 

OK, using the suggested Fiddler app to check the server responses I noticed it was hitting the server, but only once while in FireFox it was hitting the server every two seconds as it is supposed to. Because of the short update interval I never noticed the update in IE. Upon further investigation, IE apparently caches all GET requests and re-serves the old request if the same request is made later. To prevent this, you have to send header info to the browser to not cache the result. Adding the following code to the php script below the content-type declaration resolved the issue:

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");