In the YII framework, in order to prevent CSRF attacks, encapsulated the CSRF token authentication, when using the Yii form to generate a page, if the form is submitted as post, a hidden field will be added to the page:
<div style="display:none"> <input type="hidden" value="a429b6c0f4468db23a5661d1682db537fe2672c7" name="YII_CSRF_TOKEN" /></div>
Form Submission Resolution 1:
Write this in the way your controller is constructed.
public function init() {
$this->enablecsrfvalidation = false;
}
(Do not know what the Init method means, refer to Yii2 automatic loading)
Form Submission Resolution 2:
<input name="_csrf" type="hidden" id="_csrf" value= " <?= Yii:: $app- >request->csrftoken ?> ">
Ajax Solution 1:
var Csrftoken = $ (' meta[name="Csrf-token"] '). attr ("content");
$.ajax ({
Type: 'POST ',
Url:url,
< Span class= "Hljs-params" > data: {_ Csrf:csrftoken},
< Span class= "Hljs-params" > success:success,
< Span class= "Hljs-params" > datatype:datatype
< Span class= "Hljs-params" > });
YII2 form submission always error or page script write Ajax, with Firbug debugging always can't find address page 404