2012-07-19 100 views
5

我遇到了一個問題,掙扎了好幾個小時。我使用jQuery負荷加載一個PHP網頁,其中包含了tinyMCE其腳本(WordPress的)當我通過jQuery加載tinyMCE時,瀏覽器凍結.load()

$('.quickedit_form_' + parentID).load('<?php bloginfo('template_directory'); ?>/ajax/quickedit.php?id=' + parent.attr('id').replace('post-', ''), function(){ 
     tinyMCE.init({ 
      skin: 'wp_theme' 
     }); 
     $.scrollTo(parent, 800, {offset: {left: 0, top: -61}}); 
    }); 

而且我的PHP頁面(quickedit.php)

<?php 

// include WordPress 
require('../../../../wp-blog-header.php'); 

// get post 
global $current_user; 
$id = $_GET['id']; 
$post = get_post($id); 
if ($current_user->ID != $post->post_author) { 
    wp_die(__('Unauthorized access.','sofa')); 
} 

?> 

<h1 class="quickedit_h"><?php printf(__('Editing Post #%s','sofa'), $post->ID); ?></h1> 

<label for="edit_title_<?php echo $id; ?>" class="quickedit_label"><?php _e('Title:','sofa'); ?></label> 
<input type="text" name="edit_title_<?php echo $id; ?>" id="edit_title_<?php echo $id; ?>" value="<?php echo $post->post_title; ?>" class="quickedit_field" /> 

<label for="edit_type_<?php echo $id; ?>" class="quickedit_label"><?php _e('Post Type:','sofa'); ?></label> 
<select name="edit_type_<?php echo $id; ?>" id="edit_type_<?php echo $id; ?>" class="quickedit_select"> 
    <option value="text"<?php selected("text", sofa_post_type()); ?>><?php _e('Blog','sofa'); ?></option> 
    <option value="image"<?php selected("image", sofa_post_type()); ?>><?php _e('Image','sofa'); ?></option> 
    <option value="video"<?php selected("video", sofa_post_type()); ?>><?php _e('Video','sofa'); ?></option> 
</select> 

<div class="quickedit_save"><input type="button" value="<?php _e('Save','sofa'); ?>" class="button-secondary" /></div> 

<?php 
wp_editor($post->post_content, 'edit_content_'.$id, $settings = array(
    'wpautop' => true, 
    'media_buttons' => true, 
    'textarea_name' => 'edit_content_'.$id, 
    'textarea_rows' => 10, 
    'tabindex' => '', 
    'editor_css' => '', 
    'editor_class' => 'edit_content', 
    'teeny' => false, 
    'dfw' => false, 
    'tinymce' => true, 
    'quicktags' => true 
)); 
?> 

<div class="quickedit_save"><input type="button" value="<?php _e('Save','sofa'); ?>" class="button-secondary" /></div> 

<?php wp_footer(); ?> 

當我quickload.php直接訪問瀏覽器,一切都平穩,沒有任何延遲或任何事情。但是,當我通過jQuery .load()訪問它時,tinymce和按鈕需要大約15秒才能加載,在Firefox和Chrome中嘗試使用凍結瀏覽器(用戶無法與任何內容交互)。

任何人都可以建議我爲什麼發生這種情況,一直小時,這個嘗試.. :(

注:當我訪問quickedit.php直接TinyMCE的加載罰款,並迅速崩潰/凍結髮生在從jQuery的.load功能其稱爲

我需要的任何方向這可能是導致這個問題

+0

我與.get()有相同的問題通過我的調試器,它爲我加載jquery.min.ui.js文件時凍結 - 與asynch無關。它只會凍結/緩慢加載頁面上的第一個.get()請求,隨後的任何請求都會按預期進行響應。我認爲這與我的代理服務器有關。 – elzaer 2012-10-18 01:36:00

回答

0

我會嘗試使用jQuery的低級AJAX接口:jQuery.ajax

jQuery(function($) { 
    var ajax_url = '<?php bloginfo('template_directory'); ?>/ajax/quickedit.php?id=' + parent.attr('id').replace('post-', ''); //Included for readability 
    //Check if the elem is in the DOM, if so, load it via AJAX 
    if ($('.quickedit_form_' + parentID).length >0) { 
    $.ajax({ 
     url: ajax_url 
     complete: function () { 
      tinyMCE.init({ 
      skin: 'wp_theme' 
      }); 
     $.scrollTo(parent, 800, {offset: {left: 0, top: -61}}); 
     } 
    }); 
    } 
}); 

您可能會遇到錯誤的原因是對jQuery.load的多重參數性質(加上我認爲它的棄用...?)可能會導致同步(阻塞)請求。

相關問題