Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
uncaughtSyntaxError/尝试将php变量复制到javascript变量时出现意外数字错误_Javascript_Php_Datetime - Fatal编程技术网

uncaughtSyntaxError/尝试将php变量复制到javascript变量时出现意外数字错误

uncaughtSyntaxError/尝试将php变量复制到javascript变量时出现意外数字错误,javascript,php,datetime,Javascript,Php,Datetime,我有一个程序,需要用php获取今天的日期,然后将该变量复制到javascript变量。当我这样做时,我得到一个错误uncaughtSyntaxError/意外数字。我使用的date()函数应该已经将日期时间存储为字符串,我不太明白出现此错误的原因,非常感谢您的帮助…我的代码如下: <!DOCTYPE html> <html> <head> <script> var tmr;// timer var incidentReloader; functi

我有一个程序,需要用php获取今天的日期,然后将该变量复制到javascript变量。当我这样做时,我得到一个错误uncaughtSyntaxError/意外数字。我使用的date()函数应该已经将日期时间存储为字符串,我不太明白出现此错误的原因,非常感谢您的帮助…我的代码如下:

<!DOCTYPE html>
<html>
<head>
<script>

var tmr;// timer
var incidentReloader;
function UpdateTable()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    var tokens = xmlhttp.responseText.split("|");

        alert(tokens[0]+",    "+tokens[1]);
    }
  }
xmlhttp.open("GET","update_ajax_test.php?date1="+newDate,true);
xmlhttp.send();
}
</script>
 </head>
<body onload="tmr=setInterval(UpdateTable,5000)">

<?php
mysql_connect("xxxxxxxxxxxxxx", "xxxxxxxxxxxxxx", "xxxxxxxxxxxxxx") or die("not logged in");
//////now selecting our database
mysql_select_db("xxxxxxxxxxxxxx") or die(mysql_error());

 $res = mysql_query("SELECT num FROM ajax_table");

$numEnter=$_GET['name'];
echo $numEnter;

echo'<form method="get" action="ajax_test.php">';
 echo'  <input type="text" name="name"><br>';
 echo' <input type="submit" name="submit" value="Submit Form"><br>';
 echo'</form>';

date_default_timezone_set('America/New_York');

var tmr;//计时器
无功事故再装载机;
函数UpdateTable()
{
var-xmlhttp;
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
var tokens=xmlhttp.responseText.split(“|”);
警报(令牌[0]+“,“+令牌[1]);
}
}
open(“GET”,“update_ajax_test.php?date1=“+newDate,true”);
xmlhttp.send();
}
var newDate=;
使用

var newDate=“”;

只需执行
var newDate=var foo=“”
$date = date('Y-m-d H:i:s');
 echo $date;

mysql_query("INSERT INTO ajax_table(num,last_updated) VALUES ('$numEnter','$date')");



echo"<table border=1 id='t1'>";
while ($row = mysql_fetch_array($res))
{

    echo"<tr><td>";
    echo $row['num'];
    echo"</td></tr>";
}

echo"</table>";




?>

 <script type="text/javascript">
 var  newDate=<? echo $date; ?>;

 </script>
 </body>
 </html>
var newDate=<? echo json_encode($date); ?>;
var newDate = "<?php echo $date ?>";