我正在通过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文件
<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测试过它。
编辑:
调用后数据以JSON形式返回。
$words = StatusProcessing::findWords($statuses, $max, $avg);
$words = 'var words = '.json_encode($words);
$this->addToView('words', $words);
(这个addToView是一个基于Smarty赋值函数的函数。)
答案 0 :(得分:0)
尝试更改
$words = 'var words = '.json_encode($words);
到
$words = json_encode($words);
你不想在你的json中使用var words =
,这是不合法的,请参阅http://json.org
答案 1 :(得分:0)
Chrome未指定此错误。在Firefox中进行调试(使用Firebug)将为您提供更多信息。