dscrb00804 2012-07-14 02:26
浏览 77
已采纳

未捕获的SyntaxError:意外的令牌}

I dont know what is happening, I have double checked my code in PHP and Javascript again and again, but are not able to find any additional }, which does not have a corresponding {, can anyone help me to take a look of the code?

Here is the PHP file, the load function can successfully load, however, when I click the button "View the log", the above message occurs.

function load($DB){
    $dbConnection = mysql_connect($DB['server'], $DB['loginName'], $DB['password']);
    if(!$dbConnection){
        die('Error! ' . mysql_error());
        }
    mysql_select_db($DB['database'], $dbConnection);
    $result = mysql_query("SELECT ClientName FROM Client");

    print "Sort by";
    print "<select id='option'>";
    print "<option value='3'>Tech</option>";
    print "<option value='4'>Client</option>";
    print "</select>";
    print "<input type='button' value='View the log' onclick='viewlog(document.getElementById('option').value)'/>";
    print "<br>";

    print "Tech Name checked in/out from";
    print "<select id='client'>";
    while($row = mysql_fetch_array($result)){
        print "<option value='".$row['ClientName']."'>".$row['ClientName']."</option>";
    }
    print "</select>";
    print "<input type='button' value='Display' onclick='display(document.getElementById('client').value)'/>";
    print "<br>";
    print "<button type='button' onclick='back.php?function=5'>Export the log to .csv</button>";
    print "<br>";
}

function viewlog($DB, $sort){
    print "<h1>repeat</h1>";
    $dbConnection = mysql_connect($DB['server'], $DB['loginName'], $DB['password']);
    if(!$dbConnection){
        die('Error! ' . mysql_error());
        }
    mysql_select_db($DB['database'], $dbConnection);
    $query = "SELECT * 
                FROM Tech AS T, Client AS C, Site AS S, Log AS L 
                WHERE T.TechID=L.TechID AND C.ClientID=L.ClientID AND S.SiteID=L.SiteID ";
    if($sort=="Tech")
        $query .= "ORDER BY T.TechName ASC, L.Time DESC";
    else if($sort=="Client")
        $query .= "ORDER BY C.ClientName ASC, L.Time DESC";
    $result = mysql_query($query) or die('Error! ' . mysql_error());; 
    print "Real-Time check in/check out<br>";
    print "<table><th><td>Tech</td><td>Client</td><td>Site</td>";
    print "<td>Date and Time</td><td>Type</td></th>";
    while($row = mysql_fetch_array($result)){
        print "<tr><td>".$row['TechName']."</td>";
        print "<td>".$row['ClientName']."</td>";
        print "<td>".$row['SiteName']."</td>";
        print "<td>".$row['Time']."</td>";
        print "<td>".$row['Type']."</td></tr>";
        }
    print "</table>";
}

function export($DB){
    $dbConnection = mysql_connect($DB['server'], $DB['loginName'], $DB['password']);
    if(!$dbConnection){
        die('Error! ' . mysql_error());
        }
    mysql_select_db($DB['database'], $dbConnection);
    $result = mysql_query("SELECT TechName, ClientName, SiteName, Time, Type
                            INTO OUTFILE 'result.csv'
                            FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED by '\"'
                            LINES TERMINATED BY '
'
                            FROM Tech AS T, Client AS C, Site AS S, Log AS L
                            WHERE T.TechID=L.TechID AND C.ClientID=L.ClientID AND S.SiteID=L.SiteID
                            ORDER BY L.Time DESC");
    $Time = date('Y_m_d_H_i');
    $fileName = "Report_" + $Time;
    header('Content-type: text/csv'); 
    header('Content-Disposition: attachment; filename="'.$fileName.'.csv"'); 
    readfile('result.csv');
}

$function = $_GET['function'];
if($function==0)
    load($DB);
elseif($function==3)
    viewlog($DB, "Tech");
elseif($function==4)
    viewlog($DB, "Client");
elseif($function==5)
    export($DB);

Below is the Javascript code:

function load(){
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(){
    //document.getElementById("action").innerHTML=xmlhttp.status;
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
        document.getElementById("action").innerHTML=xmlhttp.responseText;       
    }
}
var num = 0;
xmlhttp.open("GET","back.php?function="+num, true);
xmlhttp.send();
}

function viewlog(num){
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){
        document.getElementById("View").innerHTML=xmlhttp.responseText;         
    }
}
xmlhttp.open("GET","back.php?function="+num, true);
xmlhttp.send();
}

I have tried to hide the viewlog function in js file, also for the content in viewlog function of PHP file also, but both actions still give out the same message, I really have no idea how to debug it. Can someone give me a hand?

  • 写回答

1条回答 默认 最新

  • doormen2014 2012-07-14 02:33
    关注

    I think browsers will have trouble with you using the same quote for the attribute as for the javascript string (you do it in both, but Ill just put one example):

    onclick='viewlog(document.getElementById('option').value)'
    

    into

    onclick='viewlog(document.getElementById(&quot;option&quot;).value)'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。