简体   繁体   English

Yii2:data-method ='post'正在发送GET请求

[英]Yii2: data-method='post' is sending GET request

I am making changes in existing web page in yii2. 我正在yii2中的现有网页中进行更改。 I had this section of code: 我有这段代码:

Html::a('Confirm!',[
        'default/apply',
        'confirm' => 1,
        'id' => $data->id
    ],['class' => 'btn-primary','data-method' => 'post'])

I have moved this to a different container on the same page. 我已将其移动到同一页面上的其他容器中。

(I had to adjust slightly, changing $data->id into $projectInfo->id as earlier it was inside anonymous function within a widget and now inside a foreach loop. But this should not be relevant I suppose.) (我不得不稍作调整,将$data->id更改为$projectInfo->id因为它先前位于小部件内的匿名函数中,现在位于foreach循环中。但这与我想的无关。)

Both before and after the change the same line is present in html (but in different part of the page): 更改前后,html中均出现同一行(但在页面的不同部分):

<a class="btn-primary" href="/participant/default/apply/13/1" data-method="post">Confirm!</a>

But on execution http request is now sent as GET instead of POST. 但是在执行时,http请求现在作为GET而不是POST发送。

BEFORE: "POST /participant/default/apply/13/1 HTTP/1.1" 之前: "POST /participant/default/apply/13/1 HTTP/1.1"

NOW: "GET /participant/default/apply/13/1 HTTP/1.1" 现在: "GET /participant/default/apply/13/1 HTTP/1.1"

I cannot figure out why this changed and how to get the code to work as POST in new location. 我不知道为什么会更改,以及如何使代码在新位置作为POST工作。 This href execution must depend on some additional factor that I am not aware of. 该href执行必须取决于我不知道的一些其他因素。

You can send POST request using link thanks to JavaScript inside yii.js file that wraps it in form silently. 得益于yii.js文件中的JavaScript,您可以使用链接发送POST请求,该请求会将请求以静默方式包装成表格。 If this JS is not loaded in assets link works in standard way which is sending GET requests. 如果未将此JS加载到资产中,则链接将以标准方式工作,即发送GET请求。

Check if yii.js is loaded (usually through registering yii\\web\\YiiAsset directly or by dependency). 检查是否已加载yii.js (通常是通过直接注册yii\\web\\YiiAsset或通过依赖项注册)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM