【问题标题】:Parse error on compilation编译时解析错误
【发布时间】:2013-01-22 09:41:09
【问题描述】:

我试图研究类似的主题,但找不到解决方案,我做了所有我学到的东西,但它总是给我同样的错误,这里是代码:

        <script type="text/javascript" charset="utf-8">
        $(document).ready(function() {
            $('#example').dataTable();
                      } ); //this is where its pointing for error
    </script>

我不认为我遗漏了什么,但肯定还有其他错误……你们中的任何人都可以指出吗?

这是错误详情:

解析错误:语法错误,意外 '}',期待 ',' 或 ';'在 /var/www/vhosts/tradeglobus.com/httpdocs/companies_list.php 第 41 行


@Alex:这是完整的代码

$isSeller = ((isset($PageType) && $PageType == "sellers") ? "1" : "0");

if(isset($searchType) && $searchType == "companies")
{
    //--------- Show Products Here -----------//
    $Query = clsCompanies::searchCompany($keyword, $Limit, $Offset, $countryID);
    $companies_list = $objDatabase->runStoredProcedure($Query);
    //----------------------------------------//
}
else
{
    //--------- Show Products Here -----------//
    $Query = clsCompanies::getCompaniesForDetailPages($IndustryId, $isSeller, $Limit, $Offset);
    $companies_list = $objDatabase->runStoredProcedure($Query);
    //----------------------------------------//
}

if(count($companies_list))
{
    $Cnt = 0;

    foreach($companies_list as $company)
    {
        $Cnt++;
        echo '<tr>
                <td ' . ((($Cnt % 2) == 0) ? "class='Even'" : "class='Odd'") . ' ">

    <style type="text/css" title="currentStyle">
        @import "http://www.tradeglobus.com/search/demo_page.css";
        @import "http://www.tradeglobus.com/search/demo_table.css";
    </style>

    <script type="text/javascript" language="javascript" src="http://www.tradeglobus.com/search/jquery.js"></script>
    <script type="text/javascript" language="javascript" src="http://www.tradeglobus.com/search/jquery.dataTables.js"></script>
    <script type="text/javascript" charset="utf-8">
        $(document).ready(function() {
            $('#example').dataTable();
                      } );
    </script>

<body id="dt_example">
    <div id="container">
        <div id="demo">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
    <tr>
        <th>Company</th>
        <th>Description</th>
        <th>Membership Status</th>
        <th>Country</th>
    </tr>
</thead>
<tbody>
    <tr class="gradeX">

    <!-- TD for Company Logo STARTS -->
    <td rowspan="3" valign="top" width="75px" valign="middle" align="center">
    <img src="' . clsPresent::checkImageExistance(BASE_HOST . DEFAULT_COMPANY_LOGO_PATH . $company['company_logo_thumb']) . '" width="75px" height="75px" alt="productImage" />
    </td>
    <!-- TD for Company Logo ENDS -->

    <!-- TD for Company Name & Description STARTS -->
    <td rowspan="2" width="450px" align="left" style="line-height: 15px;">
    <h4 ><a style="font-size:16px;" href="' . BASE_HOST . 'companies_details/' . $company['MemberID'] . '/' . clsPresent::removeSpecialChars($company['company_name']) . '.htm">' . $company['company_name'] . '
    </a></h4><br/>' . ((strlen($company['company_introduction']) > 165) ? substr(strip_tags($company['company_introduction']), 0, 162) . '...' : $company['company_introduction']) .'
    </td>
    <!-- TD for Company Name & Description ENDS -->

    <!-- TD for Company Flag & Package STARTS -->
    <td valign="top" >
    <div style="float: left; line-height: 25px;"><div class="flags f_' . $company['CountryID'] . '"></div>&nbsp;' . $company['Country'] .'</div><br/>
    </td>
    <!-- TD for Company Flag & Package ENDS -->
    <td class="center"><img src="' . BASE_HOST . DEFAULT_PACKAGE_IMAGE_PATH . $company['imagePath'] . '" alt="Package Image" width="101px" height="24px" /></td>
    </tr>
    </table>
                        <tr>    

                            <td valign="top" style="line-height: 15px;">
                                <div>';?> 
                                <?php
                                    if(isset($_SESSION['userID']) && $_SESSION['userID'] != ""){ ?>
                                        <a style="vertical-align: top;" class="contactNow" href="<?php echo BASE_HOST; ?>contactmember.php?to=<?php echo $company['MemberID']; ?>&from=<?php echo $_SESSION['userID']; ?>&subject=Contact Request"></a>
                                    <?php } else { ?>
                                        <a style="vertical-align: top;" class="contactNowB" href="<?php echo BASE_HOST; ?>signin.php"></a>
                                    <?php } 
                                    echo '</div>
                            </td>
                        </tr>

                    </table>                          
                </td>
            </tr>';
    }

    echo '<tfoot>
            <tr>
                <th>';

    if(isset($PageType) && $PageType != ""){        
        echo'       <span style="float: left; padding-left: 10px;">' . (( $PageNo > 1 ) ? '<a href="' . BASE_HOST . $PageType . '/' . $IndustryId . '/' . ( $PageNo - 1 ) . '/' . $CategoryName . '.htm"><-- Back</a>' : "" ) . '</span>
                    <span style="float: right; padding-right: 10px;"><a href="' . BASE_HOST . $PageType . '/' . $IndustryId . '/' . ( $PageNo + 1 ) . '/' . $CategoryName . '.htm">Next --></a></span>';
    }else{
        echo'       <span style="float: left; padding-left: 10px;">' . (( $PageNo > 1 ) ? '<a href="' . BASE_HOST . 'search/companies/' . (($countryID != "") ? $countryID : "0") . '/' . ( $PageNo - 1 ) . '/' . $keyword . '.htm"><-- Back</a>' : "" ) . '</span>
                    <span style="float: right; padding-right: 10px;"><a href="' . BASE_HOST . 'srch/companies/' . (($countryID != "") ? $countryID : "0") . '/' . ( $PageNo + 1 ) . '/' . $keyword . '.htm">Next --></a></span>';
    }

    echo '      </th>
            </tr>
          </tfoot>';
}
else
{
    echo '<tr>
            <td align="center" valign="top">
                <h1 style="font-size: 16px; color: #003466;">No companies were found for this category.</h1>
            </d>
          </tr>';
}
    ?>

【问题讨论】:

  • 不要在问题或其标题中放置紧急的类似子句。
  • 这似乎是 PHP 错误,而不是 javascript 语法错误。如果这就是你所有的 javascript 代码,那么它似乎没有语法错误
  • @Rajesh,兄弟,我的问题不允许发布,这就是为什么我放了一些东西让它独一无二。

标签: javascript syntax-error parse-error


【解决方案1】:

你需要引用'

$('#example').dataTable();

应该是

echo '<tr>
/*...further code...*/
$(\'#example\').dataTable();
';

因为它在 PHP 字符串中。

【讨论】:

    【解决方案2】:

    您的 JavaScript 代码没有错误。 JavaScript 不会编译,它会被浏览器解释。您不会在 JavaScript 页面中看到 Parse error,您会看到错误记录到浏览器控制台(WebInspector/Firebug 等)。

    您的错误出现在您的 PHP 代码中,我怀疑行号是否指向正确的位置。如果您需要更多调试帮助,请在您的问题中发布整个 PHP 源代码。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    • 1970-01-01
    • 1970-01-01
    • 2012-09-21
    相关资源
    最近更新 更多