wordpress 使用 ajax
  1. 获取唯一 ajaxUrl
  2. 请求参数中设置 action 请求方法
  3. functions.php 中写函数并注册

前端

var ajaxurl = '<?php echo admin_url('admin-ajax.php')?>';
$.ajax({
    url: ajaxurl,
    type: 'post',
    data: {
        action: 'addUserSubmitData',
    },
    dataType: 'json',
    success: function (res) {
    }
});
 ```

## functions.php

Ajax 请求权限

```php
// 登录用户可以请求
add_action('wp_ajax_ajaxVideoList', 'ajaxVideoList');

// 非登录用户可以请求
add_action('wp_ajax_nopriv_ajaxVideoList', 'ajaxVideoList');

了解 王坤的博客 的更多信息

订阅后即可通过电子邮件收到最新文章。

作者:kenney wang
暂无评论

发送评论 编辑评论


				
上一篇
下一篇

了解 王坤的博客 的更多信息

立即订阅以继续阅读并访问完整档案。

继续阅读