0

我试图研究类似的主题,但找不到解决方案,完成了我学到的一切,但它总是给我同样的错误,&这里是代码:

        <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>';
}
    ?>
4

2 回答 2

0

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

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

于 2013-01-22T10:07:12.350 回答
0

你需要报价'

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

应该

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

因为它在 PHP 字符串中。

于 2013-01-22T10:36:05.087 回答