如何使用$.get()或$.post()方法将输入参数传递给phpmvc中的控制器操作ajax jquery


How to pass input parameters to controller actions in php mvc with $.get() or $.post() methods ajax jquery?

如何使用$.get()$.post()方法将输入参数传递给phpmvc中的控制器动作ajax jquery?

在我的php代码中,如何将$username参数发送到checkUserName操作?我可以在$.get()$.pos() ajax中将此参数作为选项数据参数发送吗?

//my class. this class is for users
class User extends Controller
{    
    // construct class
    function __construct()
    {
        parent::__construct();
    }
    // my action. this actin check username in database
    public function checkUserName($username)
    {
      // enter code here
    }        
}

使用后方法

function get_username() {
    $.ajax({
        url:'controller/method',
        type: "post",
        data: {
            'username': username,
        },
        success: function(data) {
        },
    });
}

<?php public function checkUserName()
            {
              $username = $_POST['username'];
                  or
              $username = $_GET['username'];
            }

将获取方法的类型更改为GET