Reputation: 27
The jquery script of my program loads when there are no other elements on the file, but doesn't work when there are other code added on the page. JQuery library is loaded.
The following works ok:
<body text="#676767" link="#0000ff" vlink="#800080" alink="#ff0000">
<div id="loadmkts"></div>
<script>
var $scores = $("#loadmkts");
setInterval(function () {
$scores.load("/markets1.php?eventid=31680557&inplay=yes);
}, 5000);
</script>
</body>
The following doesn't work when other code is added to the page, e.g. the php code to use variables as the url parameters.
<body text="#676767" link="#0000ff" vlink="#800080" alink="#ff0000">
<?php
$eventid="31680557";
$inplay="yes";
$acct="100000";
?>
<div id="loadmkts"></div>
<script>
var $scores = $("#loadmkts");
var evid=<?php echo $eventid; ?>;
var inplay=<?php echo $inplay; ?>;
setInterval(function () {
$scores.load("/markets1.php?eventid="+evid+"&inplay="+inplay);
}, 5000);
</script>
</body>
Thanks for any help.
Upvotes: 0
Views: 91
Reputation: 193
You have to enclose the PHP variables in quotes - declaring string in JS. Otherwise the $inplay will print as a variable "yes" (which is undefined at this point) in the JS code.
<?php
$eventid="31680557";
$inplay="yes";
$acct="100000";
?>
<div id="loadmkts"></div>
<script>
var $scores = $("#loadmkts");
var evid='<?php echo $eventid; ?>';
var inplay='<?php echo $inplay; ?>';
setInterval(function () {
$scores.load("/markets1.php?eventid="+evid+"&inplay="+inplay);
}, 5000);
</script>
</body>
Upvotes: 1