我正在通过 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 的 assign 函数的函数。)