如何使用$.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