未捕获的SyntaxError:意外的标记ILLEGAL

时间:2012-12-02 13:59:11

标签: php javascript jquery cakephp-2.1

我遇到类似这样的问题: Uncaught SyntaxError: Unexpected Token - jQuery - Help!

我正在使用CakePHP 2.x生成jquery AJAX请求。它在我的本地设置上工作正常,但在生产服务器上失败,给我一个未被捕获的SyntaxError:

未捕获的SyntaxError:意外的标记ILLEGAL

这是PHP:

// Get the select element by its generated id attribute.
echo $this->Js->get('#'.$equipment_code)->event(
    // Change in the dropdown selection
    'change',
    // Request an array of compatible brands (match model type)
    $this->Js->request(
        array('controller'=>'builds','action'=>'ajax_brands'),
        // Update the associated brand dropdown
        array('update' => $hashed_brand_code, 'dataExpression' => true, 'data' => '$("#'.$equipment_code.'").serialize()')
    )
);

生成此脚本:

<script type="text/javascript">
//<![CDATA[
$(document).ready(function () {
    $("#equipment-14-0").bind("change", function (event) {
        $.ajax({
            data:$("#equipment-14-0").serialize(), 
            dataType:"html", 
            success:function (data, textStatus) {
                $("#brand-14-0").html(data);}, 
                url:"\/proj\/eztek-dev\/builds\/ajax_brands"
            });
            return false;
        });
    $("#brand-14-0").bind("change", function (event) {
        $.ajax({
            data:$("#brand-14-0,#equipment-14-0").serialize(),
            dataType:"html", 
            success:function (data, textStatus) {
                $("#model-14-0").html(data);
            }, 
            url:"\/proj\/eztek-dev\/builds\/ajax_models"
        });
        return false;
    });
    $("#equipment-14-2").bind("change", function (event) {
        $.ajax({
            data:$("#equipment-14-2").serialize(), 
            dataType:"html", 
            success:function (data, textStatus) {
                $("#brand-14-2").html(data);
            }, 
            url:"\/proj\/eztek-dev\/builds\/ajax_brands"
        });
        return false;
    });
    $("#brand-14-2").bind("change", function (event) {
        $.ajax({
            data:$("#brand-14-2,#equipment-14-2").serialize(), 
            dataType:"html", 
            success:function (data, textStatus) {
                $("#model-14-2").html(data);
            }, 
            url:"\/proj\/eztek-dev\/builds\/ajax_models"
        });
        return false;});
    });
//]]>
</script>

这是stack trace

我非常感谢您提供的任何帮助,如果有任何其他有用的信息,请告诉我,我会尽快提出来。

谢谢!

编辑:

谢谢大家的帮助。我通过删除js文件中的未接受字符来修复未捕获的语法错误,但是AJAX仍然无法在生产服务器上运行。我在控制台中收到以下错误:

Failed to load resource: the server responded with a status of 500 (Internal Server Error) 
{Domain name} /proj/eztek-dev/builds/ajax_brands?data%5BEzcomponent%5D%5B2%5D%5Bezmodel_type_id%5D=5

Network requests http://resaraos.com/proj/screenshot2.png

serialize()会出现问题吗?

2 个答案:

答案 0 :(得分:0)

我只想指出你生成php代码的方式非常实用。

$arr1 = array(
    'controller'=>'builds',
    'action'=>'ajax_brands'
);

$arr2 = array(
    'update' => $hashed_brand_code, 
    'dataExpression' => true, 
    'data' => '$("#'.$equipment_code.'").serialize()'
);

$jsRequest = $this->Js->request($arr1, $arr2);
$jsGet = $this->Js->get('#'.$equipment_code)->event('change', $jsRequest); // Change in the dropdown selection & update the associated brand dropdown

$echo $jsGet;

有点像是有道理的。

很抱歉回答一个旧帖子(没有回答问题的真实答案),这真的让我眼前一亮。

答案 1 :(得分:0)

对任何绊倒这个问题的人都提出了暗示:

Chrome未指定此特定错误。使用Firefox(Firebug控制台)获取有关错误的更多信息。

相关问题