我遇到了一个问题,挣扎了好几个小时。我正在使用jQuery加载来加载包含tinyMCE及其脚本(wordpress)
的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()访问它时,在Firefox和chrome中尝试加载和冻结浏览器(用户无法与任何东西进行交互)时,需要大约15秒钟。
任何人都可以告诉我为什么会发生这种情况,经过几个小时尝试这个...... :(
注意:当我直接访问quickedit.php时,tinymce会很好地加载。当从jquery .load函数调用它时发生崩溃/冻结。
我需要任何可能导致此问题的指示?
答案 0 :(得分: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的多参数性质(加上我认为它已被弃用......?)可能会导致同步(阻塞)请求。