2

我正在开发带有帮助插件的wpmvc插件。我面临 Ajax 调用的问题。

我已经添加了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”响应

4

3 回答 3

0

Check this URL so that it may help you:

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

I too am looking for the same thing as you do... If you arrive at a solution please do share it so that i too can solve the issue...

于 2014-12-02T10:57:21.407 回答
0

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

于 2013-10-09T13:38:12.117 回答
0
  1. your-plugin/app/config/router.php文件中添加:

    MvcRouter::admin_ajax_connect(array('controller' => 'adminprojects', 'action' => 'ajaxshow'));
    
  2. your-plugin/controllers/admin/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);
        });
    });
    
于 2016-12-21T19:30:56.087 回答