问题描述
我正在通过jQuery进行AJAX调用,导致上述错误.奇怪的是,代码可以在LAMP,WAMP上正常工作,但是当将其移植到真实服务器时,就会出现问题.
I am making an AJAX call via jQuery which results in the above mentioned error. The strange part is the code works fine on LAMP, WAMP but when it is ported to a real server its giving the problem.
这是我的AJAX电话:
Here's my AJAX call:
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文件
Here's the Smarty .tpl file that is loaded from the AJAX call
<script type="text/javascript">{$words}</script>
<script type="text/javascript" src="{$site_root_path}extlib/jQCloud/jqcloud-1.0.0.min.js"></script>
<link rel="stylesheet" type="text/css" href="{$site_root_path}extlib/jQCloud/jqcloud.css" />
<script type="text/javascript">
$(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);
});
</script>
<style type="text/css">
#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;
}
</style>
{/literal}
<link rel="stylesheet" type="text/css" href="{$site_root_path}assets/css/popup.css" />
<script type="text/javascript" src="{$site_root_path}assets/js/popup.js"></script>
仅在真实服务器上而不在LAMP,WAMP上出现此错误的原因可能是什么?我基本上已经用chrome测试过了.
What could be the reason for such an error that too only on a real server and not on LAMP, WAMP ? I've basically tested it with chrome.
数据在调用后以JSON的形式返回.
The data is returned as JSON after the call.
$words = StatusProcessing::findWords($statuses, $max, $avg);
$words = 'var words = '.json_encode($words);
$this->addToView('words', $words);
(此addToView是一个基于Smarty的assign函数的函数.)
(this addToView is a function that builds upon Smarty's assign function.)
推荐答案
Chrome浏览器未指定此错误.在Firefox中进行调试(使用Firebug)将为您提供更多信息.
Chrome doesn't specify this error. Debugging in Firefox (using Firebug) will give you more information.
这篇关于未捕获到的SyntaxError:意外的令牌非法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!