From 32f5c17ffc71eed59378818c75dc7d4723180427 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Fri, 11 Nov 2016 00:26:37 +0800 Subject: [PATCH] =?UTF-8?q?modified=20=E6=96=B0=E5=A2=9Eajax=20put?= =?UTF-8?q?=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/User.php | 8 ++--- public/admin/static/js/template.js | 46 +++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/application/admin/controller/User.php b/application/admin/controller/User.php index 1005ed5..dbf9b34 100644 --- a/application/admin/controller/User.php +++ b/application/admin/controller/User.php @@ -64,19 +64,19 @@ class User extends Base { [ 'info' => '启用', 'href' => url('User/open'), - 'class'=> 'btn-success', + 'class'=> 'btn-success ajax-put-url', 'param'=> [$this->primaryKey], 'icon' => 'fa fa-check', - 'confirm' => 0, + 'confirm' => 1, 'show' => ['status', 0] ], [ 'info' => '禁用', 'href' => url('User/close'), - 'class'=> 'btn-warning', + 'class'=> 'btn-warning ajax-put-url', 'param'=> [$this->primaryKey], 'icon' => 'fa fa-close', - 'confirm' => 0, + 'confirm' => 1, 'show' => ['status', 1] ], [ diff --git a/public/admin/static/js/template.js b/public/admin/static/js/template.js index 280554d..dc8a6d7 100644 --- a/public/admin/static/js/template.js +++ b/public/admin/static/js/template.js @@ -220,6 +220,52 @@ return false; }); + /** + * Ajax put by url 请求(改) * + */ + bodyDom.on('click', '.ajax-put-url', function() { + var url = $(this).attr('url'), urlData = ''; + if( $(this).attr('data') ){ + urlData = $(this).attr('data'); + } + if( $(this).hasClass('confirm') ){ + bootbox.confirm({ + title: "温馨提醒:", + message: "您确定要这么做么?", + buttons: { + cancel: { + label: ' 取消' + }, + confirm: { + label: ' 确定' + } + }, + callback: function (result) { + if( result ){ + $.ajax({ + type: "PUT", + url: url, + data: urlData + }).done(function( data ) { + var wait = 1000*data.wait; + if (data.code == 1) { + $.alertMsg(data.msg); + setTimeout(function() { + if (data.url) { + $.refresh(data.url); + } + }, wait); + } else { + $.alertMsg(data.msg); + } + }); + } + } + }); + } + return false; + }); + /** * Ajax 刷新页面 * */