如何通过WordPress中的wp-mvc插件进行ajax调用



我正在插件的帮助下开发插件wpmvc。我面临阿贾克斯电话的问题。

我已经添加了router.php文件。

MvcRouter::admin_ajax_connect(array('controller' => 'tbl_projects', 'action' => 'show'));

我在控制器文件中创建了show()操作,并在视图文件夹中创建了show.php文件。我在js文件中添加了js函数:

        url : ajaxurl,
        data : {
            action : 'tbl_projects_controller_show',
            postData : ''
        },
        dataType : "html",
        type : 'post',

当Ajax调用时,我得到"0"响应

以下内容应该可以帮助您继续前进:http://codex.wordpress.org/AJAX_in_Plugins

检查此 URL,以便它可以帮助您:

http://solislab.com/blog/5-tips-for-using-ajax-in-wordpress/

我也在寻找和你一样的东西...如果您找到解决方案,请分享它,以便我也可以解决问题......

  1. 在您的插件/应用程序/配置/路由器中.php文件添加:

    MvcRouter::admin_ajax_connect(array('controller' => 'adminprojects', 'action' => 'ajaxshow'));
    
  2. 在您的插件/控制器/管理员/admin_projects_controller.php中文件添加:

    class AdminProjectsController extends MvcAdminController {
        public function ajaxshow() {
            // also can use $_POST['content']
            echo 'GOT IT:' . $this->params['content'];
            die();
        }
    }
    

    注意:控制器类名和控制器变量传入admin_ajax_connect函数。

  3. 现在您可以使用如下代码:

    jQuery(document).ready(function() {
        // Data to send to the AJAX call
        var data = {
            action: 'adminprojects_ajaxshow',
            content: 'Run from myplugin ajax'
        };
        // ajaxurl is defined by WordPress
        jQuery.post(ajaxurl, data, function (response) {
            // Handle the response
            console.log(response);
        });
    });
    

最新更新