Answer the question
In order to leave comments, you need to log in
Yii2 ajax js request not finding action?
routes:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'' => 'site/index',
'sendMail' => 'site/sendMail',
],
]<img src="https://habrastorage.org/webt/5e/00/bb/5e00bbe8e081b833076907.png" alt="image"/>
public function actionSendMail() {
$dataMessage = [
'name' => trim( strip_tags( Yii::$app->request->post('name', '') ) ),
'email' => trim( strip_tags( Yii::$app->request->post('email', '') ) ),
'number' => trim( strip_tags( Yii::$app->request->post('number', '') ) ),
'message' => trim( strip_tags( Yii::$app->request->post('message', '') ) )
];
$miler = new SendMail();
return $miler->SendMail($dataMessage);
}
fetch('/sendMail', {
method: 'post',
body: new FormData(form)
}).then((response) => {
response.text().then((data) => {
console.log(data);
});
});
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