Uncaught SyntaxError: Unexpected token ILLEGAL

霸气de小男生 提交于 2019-12-13 16:25:16

问题


I am encountering a problem similar to this: Uncaught SyntaxError: Unexpected Token - jQuery - Help!

I am using CakePHP 2.x to generate a jquery AJAX request. It works fine on my local setup, but fails on a production server, giving me an uncaught SyntaxError:

Uncaught SyntaxError: Unexpected token ILLEGAL

This is the 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()')
    )
);

Which generates this script:

<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>

And here is the

I'd really appreciate any help you can offer, if there is any other information that would be useful, please let me know and I will put it up here asap.

Thank you!

EDIT:

Thank you all for your help. I have fixed the uncaught syntax error by removing unaccepted characters in the js files, however the AJAX still doesn't work on the production server. I get the following error in the console:

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


(source: resaraos.com)

Could something be going wrong with the serialize()?


回答1:


I just want to point out that the way you generate your php code is quite im-practical.

$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;

Something like would make sense.

Sorry for answering an old post (without really answering with a real answer to the question), this just really pierced my eyes.




回答2:


Late hint for anyone stumbling upon this question:

This particular error is not specified by Chrome. Use Firefox (Firebug console) to get more info about the error.



来源:https://stackoverflow.com/questions/13669954/uncaught-syntaxerror-unexpected-token-illegal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!