5

問題が発生し、何時間も苦労しました。jQuery ロードを使用して、tinyMCE とそのスクリプト (ワードプレス) を含む php ページをロードしています。

    $('.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 関数から呼び出されたときにクラッシュ/フリーズが発生します。

この問題の原因について何か指示が必要ですか?

4

1 に答える 1

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 の複数の引数の性質によるものです (さらに、非推奨だと思います...?) 同期 (ブロッキング) 要求を引き起こしている可能性があります。

于 2012-12-27T19:27:32.483 に答える