2012-07-13 64 views
0

我正在通過jQuery進行AJAX調用,導致上述錯誤。奇怪的部分是代碼在LAMP,WAMP上工作正常,但是當它移植到真正的服務器時,它提供了問題。未捕獲的SyntaxError:意外的令牌非法?

這裏是我的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?我基本上用鉻進行了測試。

編輯:

的數據被調用後返回的JSON。

$words = StatusProcessing::findWords($statuses, $max, $avg); 
$words = 'var words = '.json_encode($words); 
$this->addToView('words', $words); 

(這addToView是建立在Smarty的分配功能的功能。)

+0

*「數據在調用後以JSON形式返回。」*我沒有看到任何JSON。你說過ajax調用正在加載Smarty模板。該模板肯定不會返回JSON。 – 2012-07-13 12:22:35

+0

@TJCrowder iive現在把JSON放在問題 – eku 2012-07-13 12:43:40

+0

@TJCrowder它是一個非常大的項目,我不認爲問題會出現在PHP部分,所以我沒有把它放在問題中第一名。無論如何,它現在和整個代碼在這裏:https://github.com/ekanshpreet/data-portraits – eku 2012-07-13 12:51:06

回答

0

嘗試改變

$words = 'var words = '.json_encode($words);

$words = json_encode($words);

你不想要var words =在您的json中,這是不合法的,請參閱http://json.org

0

Chrome未指定此錯誤。在Firefox中調試(使用Firebug)將爲您提供更多信息。

相關問題