2016-11-14 31 views
0

我在一頁上使用「tinyMCE」作爲動態頁面。如何檢查jquery中的「is_file」

所以我必須使用「setContent」來更改「tinyMCE」中的內容。

但是,我不知道如何檢查is_file(在PHP中檢查文件存在與否)在ajax中或之前去ajax。

請讓我知道〜

 $(".editor-button").bind("click", function(){ 
      var title, file; 
      title = $(this).data("title");     
      $(".ui-dialog-title").text(title); 
      switch (match_arr[title]) { 
       case 1: 
        file = "../../front/footer/about_us.html"; 
        break; 
       case 2: 
        file = "../../front/footer/return_policy.html"; 
        break; 
       default: 
      } 

      $.ajax({ 
       url : file, 
       dataType: "html", 
       success : function (html){ 
        html != "" ? tinyMCE.get('text-box').setContent(html) : tinyMCE.get('text-box').setContent(''); 
       } 
      }); 

      $("#text-editor-dialog").dialog("open"); 
     }); 

回答

0

我改成了像下面的Ajax代碼和它的作品。

  $.ajax({ 
       url : file, 
       dataType: "html", 
       success : function (html){ 
        tinyMCE.get('text-box').setContent(html); 
       }, 
       error : function(){ 
        tinyMCE.get('text-box').setContent(''); 
       } 
      });