Answer the question
In order to leave comments, you need to log in
Why is ajax request not working in yii2?
Are there any special request criteria for yii2? no matter how I twist everything 400, it throws an error (bad request)
$(document).ready(function () {
$.ajax({
type: "POST",
url: "<?php echo Yii::$app->getUrlManager()->createUrl('/partner/ajax') ; ?>",
data: {test: "test"},
success: function (data) {
alert(JSON.stringify(data));
},
error: function (exception) {
alert(JSON.stringify(exception));
}
});
});
public function actionAjax()
{
if(!empty(Yii::$app->request->post('test'))){
$test = "Ajax Worked!";
}else{
$test = "Ajax failed";
}
return $test;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question