新增加Ajax数据提交函数

This commit is contained in:
zhaoxiang 2016-11-05 17:34:32 +08:00
parent 8fadb2bc27
commit acf70354ec
3 changed files with 91 additions and 55 deletions

View File

@ -65,4 +65,8 @@ class User extends Base {
return $this->fetch(); return $this->fetch();
} }
} }
public function add(){
}
} }

View File

@ -21,7 +21,7 @@
<div class="login-box-body"> <div class="login-box-body">
<p class="login-box-msg">请填写您的账号名和密码</p> <p class="login-box-msg">请填写您的账号名和密码</p>
<form action="{:url('User/login')}" method="post"> <form action="{:url('User/login')}" id="form-login">
<div class="form-group has-feedback"> <div class="form-group has-feedback">
<input type="text" class="form-control" name="username" placeholder="Username"> <input type="text" class="form-control" name="username" placeholder="Username">
<span class="glyphicon glyphicon-user form-control-feedback"></span> <span class="glyphicon glyphicon-user form-control-feedback"></span>
@ -32,7 +32,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<button type="submit" class="btn btn-primary btn-block btn-flat">登 录</button> <span type="submit" target-form="form-login" class="btn btn-primary ajax-post btn-block btn-flat">登 录</span>
</div> </div>
</div> </div>
</form> </form>
@ -43,6 +43,10 @@
<script src="__STATIC__/jQuery/2.2.4/jquery.min.js"></script> <script src="__STATIC__/jQuery/2.2.4/jquery.min.js"></script>
<!-- Bootstrap 3.3.6 --> <!-- Bootstrap 3.3.6 -->
<script src="__STATIC__/bootstrap/js/bootstrap.min.js"></script> <script src="__STATIC__/bootstrap/js/bootstrap.min.js"></script>
<!-- BootBox -->
<script src="__ADMIN__/plugins/bootBox/bootbox.min.js"></script>
<script src="__ADMIN__/dist/js/template.js"></script>
</body> </body>
</html> </html>

View File

@ -4,13 +4,16 @@
* You should not use this file in production. * You should not use this file in production.
* This file is for demo purposes only. * This file is for demo purposes only.
*/ */
$.AdminTemplate = {};
/** (function ($) {
"use strict";
$(function() {
/**
* 格式化时间戳为了和PHP的date函数统一这里的时间戳都是10位不包含毫秒 * 格式化时间戳为了和PHP的date函数统一这里的时间戳都是10位不包含毫秒
* @param timestamp * @param timestamp
* @returns {string} * @returns {string}
*/ */
var formatDate = function ( timestamp ) { $.formatDate = function ( timestamp ) {
timestamp *= 1000; timestamp *= 1000;
var date = new Date(timestamp); var date = new Date(timestamp);
var Y = date.getFullYear() + '-'; var Y = date.getFullYear() + '-';
@ -20,13 +23,19 @@ var formatDate = function ( timestamp ) {
var m = date.getMinutes() + ':'; var m = date.getMinutes() + ':';
var s = date.getSeconds(); var s = date.getSeconds();
return Y+M+D+h+m+s; return Y+M+D+h+m+s;
}; };
(function ($, AdminTemplate) { $.alertMsg = function( msg ){
var dialog = bootbox.dialog({
message: '<p class="text-center">'+msg+'</p>',
closeButton: false
});
setTimeout(function(){
dialog.modal('hide');
}, 2000);
};
"use strict"; $.buildDom = function ( jsonStr ) {
AdminTemplate.buildDom = function ( jsonStr ) {
}; };
@ -69,18 +78,37 @@ var formatDate = function ( timestamp ) {
}; };
AdminTemplate.a = function () { //ajax post submit请求
$('body').on('click', '.ajax-post', function() {
var message,query,form,target;
var target_form = $(this).attr('target-form');
}; if ( $(this).attr('type') == 'submit' ) {
form = $('#' + target_form);
AdminTemplate.alertMsg = function( msg ){ query = form.serialize();
var dialog = bootbox.dialog({ target = form.attr('action');
message: '<p class="text-center">'+msg+'</p>', $.post(target, query).success(function(data) {
closeButton: false if (data.status == 1) {
}); if (data.url) {
setTimeout(function(){ message = data.msg + ' 页面即将自动跳转~';
dialog.modal('hide'); } else {
}, 3000); message = data.msg;
} }
$.alertMsg(message);
setTimeout(function() {
if (data.url) {
location.href = data.url;
} else {
location.reload();
}
}, 2000);
} else {
$.alertMsg(data.msg);
}
});
}
return false;
});
});
})(jQuery, $.AdminTemplate); })(jQuery);