I'm trying to send an array to an action from a controller in Yii but I'm getting 404 all the time. This is how I'm sending the data from javascript:
$.ajax({
url: baseUrl + '/user/validateUser',
data: $('#usr').val(),
type: 'post',
dataType: 'json',
success: function(res)
{
console.log(res);
}
});
In my UserController i have the following action:
public function actionValidateUser() {
if ($_POST > 0){
$username = $_POST['username'];
var_dump($username);
}
}
I'm getting this response:
Request URL:http://localhost/myapp/user/validateUser
Request Method:POST
Status Code:404 Not Found
What am I doing wrong? In Zend I did this and it worked just fine. Here ... I don't know.
UrlManagersettings. You get 404 when You openhttp://localhost/myapp/user/validateUser? Also You can try to use relative path/user/validateUserinsteadbaseUrl + '/user/validateUser'http://localhost/myapp/index.php?r=user/validateUserin the browser? If you get a 200 OK response there is something wrong with your .htaccess rewrite. BTW you should not do aif ($_POST > 0). Better would beif (isset($_POST) && count($_POST))if you want to check for an existing POST array.