Php 通过jQuery.load()加载tinyMCE时浏览器冻结
我遇到了一个问题,挣扎了几个小时。我使用jQueryLoad加载包含tinyMCE及其脚本(wordpress)的php页面Php 通过jQuery.load()加载tinyMCE时浏览器冻结,php,jquery,tinymce,Php,Jquery,Tinymce,我遇到了一个问题,挣扎了几个小时。我使用jQueryLoad加载包含tinyMCE及其脚本(wordpress)的php页面 $('.quickedit_form_u'+parentID).load('/ajax/quickedit.php?id='+parent.attr('id').replace('post-',''),function(){ tinyMCE.init({ 皮肤:“wp_主题” }); $.scrollTo(父对象,800,{offset:{left:0,top:-61}}
$('.quickedit_form_u'+parentID).load('/ajax/quickedit.php?id='+parent.attr('id').replace('post-',''),function(){
tinyMCE.init({
皮肤:“wp_主题”
});
$.scrollTo(父对象,800,{offset:{left:0,top:-61}});
});
和我的php页面(quickedit.php)
我会尝试使用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(函数($){
var ajax_url='/ajax/quickedit.php?id='+parent.attr('id')。replace('post-','');//为了可读性而包括在内
//检查元素是否在DOM中,如果是,则通过AJAX加载它
if($('.quickedit\u form\u'+parentID).length>0){
$.ajax({
url:ajax\uurl
完成:函数(){
tinyMCE.init({
皮肤:“wp_主题”
});
$.scrollTo(父对象,800,{offset:{left:0,top:-61}});
}
});
}
});
您可能会遇到错误的原因是jQuery.load的多参数性质(加上我认为它已弃用的…?)可能会导致同步(阻塞)请求。我对.get()也有同样的问题。通过我的调试器,它在为我加载jQuery.min.ui.js文件时被冻结-与异步无关。它只冻结/缓慢加载页面上的第一个.get()请求,任何后续请求都会按预期响应。我认为这对我来说与代理服务器有关。
<?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(); ?>
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}});
}
});
}
});