2012-09-05 24 views
2

所以我在我的應用程序中使用tinyMce,但是我收到了一個JavaScript錯誤,我似乎無法弄清楚如何調試。錯誤是「TypeError:P is undefined」 - 我可以從FireBug看到,但我不知道如何獲取更多/更好的信息?如何在第三方代碼中調試javascript undefined錯誤。

我試圖打開「打破所有錯誤」,但只是顯示我最小化的JS文件,我甚至不能在那裏看到一個名爲「P」的變量,所以我猜測我正在吠叫錯誤的樹。整個事情工作正常,除非我點擊保存。

聳肩我只是停留在那一刻。這是我的完整代碼。你可以看到我試圖刪除所有的插件,認爲可能是它,但沒有骰子。

很顯然,我需要解決的問題是,這是爲什麼發生的事情 - 更好的解決方案是如何找出什麼是真正導致它因此,當這樣的事情再次發生,我可以找出自己。

謝謝 - 請參閱下面的完整代碼。

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> 

    <script type="text/javascript"> 
     $(document).ready(function() { 

      $('textarea.tinymce').tinymce({ 
       script_url: '/Scripts/TinyMCE/tiny_mce.js', 
       theme: "advanced", 
       plugins: "save", 
       theme_advanced_buttons1: "save", 
//    plugins: "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template", 
//    theme_advanced_buttons1: "save,cut,copy,paste,pastetext,pasteword,|,search,replace,|,bold,italic,underline,strikethrough,|,print,|,iespell", 
       theme_advanced_toolbar_location: "top", 
       theme_advanced_toolbar_align: "left", 
       theme_advanced_statusbar_location: "bottom", 
       save_enablewhendirty: true, 
       encoding: "xml", 
       theme_advanced_resizing: true, 
       mode: "textareas", 
       save_onsavecallback: "ajaxSave", 
       setup: function(ed) { 
        ed.onSaveContent.add(function(i, o) { 
         o.content = o.content.replace(/&#39/g , "&apos"); 
        }); 
       } 
      }); 

      function ajaxSave() { 
       alert("ajaxSave called."); 
      } 

     }); 

    </script> 
    <% Html.BeginForm("Index", "DisabilityReport", FormMethod.Post); %> 
    <%= Html.AntiForgeryToken() %> 
    <%= Html.ModelData() %> 
    <textarea name="documentContent" class="tinymce" cols="90" rows="60"></textarea> 
    <% Html.EndForm();%> 
</asp:Content> 
+0

如果沒有源代碼,它會非常困難,我會說。你總是可以使用美化工具(http://jsbeautifier.org/)來取消縮小,但這當然是更好的解決方法。 – fresskoma

+0

Firebug會告訴你哪一行(以及哪個JS文件)發生錯誤。這將有助於縮小發生錯誤的位置。 – honyovk

回答

3

我不知道Firebug的,但如果你使用Chrome,在Chrome開發者工具可以擴大壓縮JS,使其更容易追蹤這些錯誤。請參見下面的括號按鈕:

enter image description here

+0

所以我用鉻,這確實有一點幫助,但它告訴我「未捕獲TypeError:不能調用方法'應用'未定義」 - 我看着它吐出的代碼,並沒有適用... Uhg。 – Kenn

+0

'apply'是JavaScript中每個函數的一個方法,但它似乎是你的變量不是一個函數,但未定義。 –

+0

隨着一點點的挖掘,我發現你可以加載tiny_mce_src.js版本,然後你不會得到縮小的文件,但我標記爲答案,因爲Chrome有一個很好的調試器,我很容易找到這個錯誤。去看代碼! ajaxSave的定義在哪裏?衛生署! – Kenn

0

Firefox有一點點的插件叫JS Deminifier,它可以在飛行deminify代碼。唯一的缺點是它有時會在這個過程中產生錯誤。

很高興讓你在找什麼的想法,但不要完全依賴它。

相關問題