Wordpress wp_ajax使用UI jquery对话框返回0面向对象插件
我试图在一个带有ui jquery对话框的对话框中使用ajax触发一个动作,但是wp_ajax它总是返回cero,我的插件它都是面向对象的,我已经找到了信息,但仍然不起作用 我的代码Wordpress wp_ajax使用UI jquery对话框返回0面向对象插件,jquery,ajax,wordpress,jquery-ui-dialog,Jquery,Ajax,Wordpress,Jquery Ui Dialog,我试图在一个带有ui jquery对话框的对话框中使用ajax触发一个动作,但是wp_ajax它总是返回cero,我的插件它都是面向对象的,我已经找到了信息,但仍然不起作用 我的代码 public function wpsgq_plugin_edit(){ echo "1"; die(); } public function wpsgq_admin_options_page() { wp_enqueue_script('jquery'); wp_enqu
public function wpsgq_plugin_edit(){
echo "1";
die();
}
public function wpsgq_admin_options_page() {
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-dialog');
wp_enqueue_style('wp-jquery-ui-dialog');
$wpdb = DB::getInstance();
$table_name = $this->prefix . 'plugin';
$rows = $wpdb->get_results( "SELECT * FROM $table_name" );
?>
<div class="wrap">
<div id="users-contain" class="ui-widget">
<h2>My Information in DB</h2>
<table id="users" class="ui-widget ui-widget-content" >
<thead>
<tr class="ui-widget-header ">
<th>ID</th>
<th>Time</th>
<th>Name</th>
<th>Text</th>
<th>URL</th>
</tr>
</thead>
<tfoot>
<tr class="ui-widget-header ">
<th>ID</th>
<th>Time</th>
<th>Name</th>
<th>Text</th>
<th>URL</th>
<th>--</th>
</tr>
</tfoot>
<tbody>
<?php
$i=1;
foreach($rows as $row){
echo "<tr>";
echo "<td class='check-column' scope='row'>".$row->id."</td>";
echo "<td class='column-columnname'>".$row->time."</td>";
echo "<td class='column-columnname'>".$row->name."</td>";
echo "<td class='column-columnname'>".$row->text."</td>";
echo "<td class='column-columnname'>".$row->url."</td>";
echo "<td class='column-columnname'>
<a id='edit_$row->id' name='edit_$row->id' onclick='show_dialog($row->id)'>Edit</a>
<div id='edit-div_$row->id' name='edit-div_$row->id' style='display: none;'>";
$item = $row->id;
${"view_".$item} = new WPSGQViews;
echo ${"view_".$item}->wpsgq_plugin_view_edit($item);
echo "</div>
</td>";
echo "</tr>";
$i++;
}
?>
</tbody>
</table>
<?php
add_action( 'wp_ajax_nopriv_wpsgq_plugin_edit', array( $this, 'wpsgq_plugin_edit' ) );
add_action( 'wp_ajax_wpsgq_plugin_edit', array( $this, 'wpsgq_plugin_edit' ) );
?>
<script type="text/javascript">
function show_dialog(id){
jQuery(function($) {
var info = $("#edit-div_"+id);
info.dialog({
'dialogClass' : 'wp-dialog',
'modal' : true,
'autoOpen' : true,
'closeOnEscape' : true,
'height' : 420,
'width' : 500,
'buttons' : {
"Edit": function() {
$.ajax({
type: "POST",
async: true,
url: ajaxurl,
data: {
action : 'wpsgq_plugin_edit',
param : $("#form-edit_"+id).serialize()
},
success: function(data){
var $newdiv = $('<div/>');
$("#message").append($newdiv);
$newdiv.html(data);
if(data==1){
}else{
$newdiv.html(data);
$newdiv.dialog({ modal: true,
buttons: {
Ok: function(){
$( this ).dialog("destroy");
$( this ).remove();
}
},
close: function() {
$( this ).dialog("destroy");
$( this ).remove();
}
});
}
},
error: function(data){
$("#message").html("Error: "+data);
}
});
},
"Cancel": function() {
$(this).dialog('close');
}
}
});
});
}
</script>
</div>
</div>
<?php
}
如果您看到任何错误,我们将不胜感激将这两行从wpsgq\u admin\u options\u页面函数调用移到构造函数中
add_action( 'wp_ajax_nopriv_wpsgq_plugin_edit', array( $this, 'wpsgq_plugin_edit' ) );
add_action( 'wp_ajax_wpsgq_plugin_edit', array( $this, 'wpsgq_plugin_edit' ) );
您必须使用Jquery ui完整版本 或者不需要更多的库跟踪 /小部件, /按钮, /可拖动, /鼠标, /职位, /可调整大小 对话框不能仅与核心一起使用 你可以找到为什么图书馆需要 通过以下链接
谢谢,我做了一些更改,wp_localize_脚本也出现了错误,但这一更改也帮助了我,现在我可以继续使用我的插件了