我在一家凉亭工作。js图形。我想要的是从php发送成员id查询,并将成员树json返回给jquery脚本。然后打印树
这是HTML表单
<form action="" method="post" id="blm_get_tree_view_meta_ajax_form" >
<?php echo $dropdown_html; ?>
<input type="hidden" name="action" value="blm_member_tree_response">
<input type="hidden" name="blm_mem_tree_meta_nonce" value="<?php echo $blm_add_meta_nonce ?>" />
<input id="<?php echo $this->plugin_name; ?>-treeview_mem_id" type="hidden" name="<?php echo "blm"; ?>[memid]" value="">
<p class="submit"><input type="button" name="get_tree" id="get_tree" class="button button-primary" value="GET TREE"></p>
</form>
这是jquery脚本
<script>
jQuery( document ).ready( function( $ ) {
"use strict";
$(\'#get_tree\').on(\'click\',function(){
var user_id = $(\'#binary-level-marketting-treeview_mem_id\').val();
//console.log(user_id);
$.ajax({
type:\'POST\',
url: params.ajaxurl,
data:{action:\'blm_member_tree_response\', user_id:user_id},
success:function(data){
if(data.status == \'ok\') {
console.log(data.nodes);
(function ($) {
var Renderer = function (canvas) {
var canvas = $(canvas).get(0);
var ctx = canvas.getContext("2d");
var particleSystem;
var that = {
// arbor.js rendering goes here.
//....
//...
}
// and renderer
$(document).ready(function () {
var data = {
nodes: data.nodes,
edges: data.edges
}
var sys = arbor.ParticleSystem(700, 700, 0.5);
sys.parameters({ gravity:true});
sys.renderer = Renderer("#viewport");
sys.graft(data);
});
});
})(this.jQuery);
php响应函数为
public function getTreeGraphView() {
if (isset($_POST[\'blm_mem_tree_meta_nonce\']) && wp_verify_nonce($_POST[\'blm_mem_tree_meta_nonce\'], \'blm_get_tree_view_meta_form_nonce\'))
{
if(!empty($_POST[\'user_id\'])){
$data = array();
$mtree = new MemberTree();
$mtree->getMemberTree($_POST[\'user_id\']);
$nodes_ = $mtree->getNode();
$edges_ = $mtree->getEdge();
$parent_ = $mtree->getParent();
$data[\'nodes\'] = $nodes_;
$data[\'edges\'] = $edges_;
echo $data;
die( \'0\' );
}
wp_die();
} else {
wp_die(__(\'Invalid nonce specified\', $this->plugin_name) , __(\'Error\', $this->plugin_name) , array(
\'response\' => 403,
\'back_link\' => \'admin.php?page=\' . $this->plugin_name.\'-product\',
));
}
}
ajax操作
$this->loader->add_action( \'admin_ajax_blm_member_tree_response\', $plugin_admin, \'getTreeGraphView\');
将脚本和本地化按原样排队。
该过程99%成功,但管理效率很高。php返回400状态代码。有以下回应
还有0追加到输出。我在函数末尾插入wpdie()
我不能再解决这个问题了。这里有专家吗?