Answer the question
In order to leave comments, you need to log in
Yii2 how to accept json?
Hello everyone - just started learning yii2
Made a form...
Made a $.ajax() submission
singup = (function () {
var name = $("#name").val();
$.ajax({
type: 'POST',
url: "site/singup",
data: name,
error: function(e) {
console.log(e);
}
});
});
public function actionSingup() {
if (Yii::$app->request->isAjax) {
// $m = Yii::$app->getRequest()->getIsAjax();
// $m = Yii::$app->getRequest()->getIsPost();
// $m = Yii::$app->getRequest()->getAuthUser();
// $m = Yii::$app->getRequest()->getQueryParams();
// $m = Yii::$app->getRequest()->getQueryString();
$m = Yii::$app->request->post();
// echo $m.'<br>';
return var_dump($m);
}
}
Answer the question
In order to leave comments, you need to log in
You are not transmitting data correctly, try like this:
Or like this:data: "name=" + name,
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question