dmstr / yii2-ajax-button

用于管理 Yii2 框架中 Ajax 调用的 Widget

安装次数: 43,003

依赖关系: 1

建议者: 0

安全: 0

星标: 4

关注者: 6

分支: 3

公开问题: 0

类型:yii2-extension

1.0.2 2022-05-06 09:38 UTC

This package is auto-updated.

Last update: 2024-09-06 14:45:26 UTC


README

基于 "JQuery" 的 Yii 2 Ajax Button。用于管理 Yii2 框架中的 Ajax 调用

用法

ajax 按钮小部件的示例用法

基本用法

dmstr\ajaxbutton\AjaxButton::widget([
  'method' => 'get',
  'url' => ['/path/to/action','name' => 'key']
]);

高级用法

dmstr\ajaxbutton\AjaxButton::widget([
 'method' => 'post',
 'params' => ['status' => 'active'],
 'url' => ['/path/to/action'],
 'options' => ['class' => 'btn btn-primary'],
 'errorExpression' => new JsExpression('function(resp,status,xhr) {if (xhr.status === 200) {button.html("Success")}}'),
 'successExpression' => new JsExpression('function(xhr) {if (xhr.status === 404) {button.html("Error");console.error(xhr.responseJSON)}}')
]);

安装

安装此扩展的首选方式是通过 composer

将仓库 URL 添加到你的 composer.json 文件的 required 部分。

"repositories": [
    {
        "type": "git",
        "url": "https://github.com/dmstr/yii2-ajax-button.git"
    }
],

你可以运行

php composer.phar require dmstr/yii2-ajax-buttoncomposer require dmstr/yii2-ajax-button

或者添加

"dmstr/yii2-ajax-button": "*"

到你的 composer.json 文件的 required 部分。