-1

Possible Duplicate:
Reference - What does this error mean in PHP?

I keep on getting a "Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$' in..."

Here's the line thats causing the problem, not sure whats going on here?

$text = "<script>window.setInterval(function(){$('#liveData').load('liveUpdate.php');}, 1000);</script>";

Thanks in advance

Community
  • 1
  • 1
derpyderp
  • 926
  • 1
  • 10
  • 15
  • 4
    Maybe you should re-read how strings work in PHP... The error is obvious :) http://www.php.net/manual/en/language.types.string.php (hint: you're using a $ inside a string delimited by double quotes) – ItalyPaleAle Oct 26 '12 at 00:11

3 Answers3

6

You should escape $ in your $text

$text = "<script>window.setInterval(function(){\$('#liveData').load('liveUpdate.php');}, 1000);</script>";

Or you just use single quote.

Because $ in double quote will be followed by a php variable name, $(XXXX is an invalid PHP variable.

So the best way is to separate javascript (jquery) into a .js file.

raidenace
  • 12,789
  • 1
  • 32
  • 35
user1283182
  • 131
  • 3
  • Second the idea of putting this into a separate file, or at least write it as plain javascript - not sure why the assignment to a PHP variable is needed? – ernie Oct 26 '12 at 00:33
0

Try this,

$text = '<script>window.setInterval(function(){$("#liveData").load("liveUpdate.php");}, 1000);</script>';
Deepak
  • 6,684
  • 18
  • 69
  • 121
0
$text = '<script>window.setInterval(function(){$("#liveData").load("liveUpdate.php");}, 1000);</script>';
raidenace
  • 12,789
  • 1
  • 32
  • 35