未捕获的SyntaxError:意外的令牌ILLEGAL?
我通过jQuery进行AJAX调用,导致上述错误。 奇怪的部分是代码在LAMP,WAMP上运行良好但是当它被移植到真实服务器时它会给出问题。
这是我的AJAX调用:
function wordAnalysis() { $("#spinner").show(); removeTopics(); $.ajax({ type: "POST", url: "{$site_root_path}pages/wordanalysis.php", data: "statuses="+json_statuses, success: function(msg){ $("#mainstage").html(msg); $("#spinner").hide(); } }); }
这是从AJAX调用加载的Smarty .tpl文件
{$words} $(document).ready(function() { var max = {$max}; var avg = {$avg}; var time_taken = {$time_taken}; var count = {$count}; var size; {literal} var text; var color; var span; var ele; var word_list = []; var table_height = $("#contentTable").height(); var orig_table_height = 563; var ratio = table_height / orig_table_height; var max_font_size = 45; for (var word in words) { if (words[word]['total'] < avg) { continue; } color = Math.floor((words[word]['url']*100)/words[word]['total']); size = Math.floor((words[word]['total']/max)*max_font_size); size = Math.round(size*ratio); var item = new Array(); item['text'] = word; item['weight'] = words[word]['total']; var html = new Array(); if (color <= 10) { html['style']= "color: #68a1ff;"; } else if (color <= 20) { html['style']= "color: #4088ff;"; } else if (color <= 30) { html['style']= "color: #2477ff;"; } else if (color <= 40) { html['style']= "color: #0060ff;"; } else if (color <= 50) { html['style']= "color: #0057e6;"; } else if (color <= 60) { html['style']= "color: #004ece;"; } else if (color <= 70) { html['style']= "color: #0044b5;"; } else if (color <= 80) { html['style']= "color: #003996;"; } else if (color <= 90) { html['style']= "color: #002c75;"; } else { html['style']= "color: #002562;"; } html['style'] += " font-size: "+size; item['html'] = html; word_list.push(item); } $("#mainstage").jQCloud(word_list); }); #mainstage span.w10, #mainstage span.w9, #mainstage span.w8, #mainstage span.w7 { text-shadow: 0px 1px 1px #ccc; } #mainstage span.w3, #mainstage span.w2, #mainstage span.w1 { text-shadow: 0px 1px 1px #fff; } {/literal}
这种错误的原因可能只是在真实的服务器上,而不是在LAMP,WAMP上? 我基本上用chrome测试过它。
编辑:
调用后,数据以JSONforms返回。
$words = StatusProcessing::findWords($statuses, $max, $avg); $words = 'var words = '.json_encode($words); $this->addToView('words', $words);
(这个addToView是一个基于Smarty赋值函数的函数。)
尝试改变
$words = 'var words = '.json_encode($words);
至
$words = json_encode($words);
你不想在你的json中使用var words =
,这是不合法的,请参阅http://json.org
Chrome未指定此错误。 在Firefox中进行调试(使用Firebug)将为您提供更多信息。