我遇到了类似的问题: Uncaught SyntaxError: Unexpected Token - jQuery - Help!
我正在使用 CakePHP 2.x 生成一个 jquery AJAX 请求。它在我的本地设置上运行良好,但在生产服务器上失败,给我一个未捕获的 SyntaxError:
Uncaught SyntaxError: Unexpected token 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>
这是
非常感谢您提供的任何帮助,如果有任何其他有用的信息,请告诉我,我会尽快把它放在这里。
谢谢!
编辑:
谢谢大家的帮助。我已通过删除 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
(来源:resaraos.com)
serialize() 可能有问题吗?