[英]How to pass input parameters to controller actions in php mvc with $.get() or $.post() methods ajax jquery?
如何使用$.get()
或$.post()
方法將輸入參數傳遞給php mvc中的控制器操作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
}
}
用post方法
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
for get方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.