Ahm*_*uad 5 php jquery tinymce
我遇到了一个问题,挣扎了好几个小时.我正在使用jQuery加载来加载包含tinyMCE及其脚本的php页面(wordpress)
$('.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}});
});
Run Code Online (Sandbox Code Playgroud)
和我的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(); ?>
Run Code Online (Sandbox Code Playgroud)
当我直接在浏览器中访问quickload.php时,一切都加载顺畅,没有延迟或任何东西.但是当我通过jQuery .load()访问它时,在Firefox和Chrome中尝试加载和冻结浏览器(用户无法与任何东西交互)的时间和按钮.
任何人都可以向我建议为什么会发生这种情况,几个小时尝试这个... :(
注意:当我直接访问quickedit.php时,tinymce会很好地加载.从jquery .load函数调用时发生崩溃/冻结.
我需要任何可能导致此问题的指示?
我会尝试使用 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}});
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
您可能遇到错误的原因是 jQuery.load 的多参数性质(加上我认为它已弃用......?)可能会导致同步(阻塞)请求。
| 归档时间: |
|
| 查看次数: |
486 次 |
| 最近记录: |