This commit is contained in:
绯村月
2014-03-12 00:15:10 +08:00
parent 8a7a41229b
commit 1c71501fde
2 changed files with 25 additions and 5 deletions

View File

@@ -1,5 +1,18 @@
$ ->
$.fn.checkAndRequest = (url, callback, opts) ->
window.pageErrorHandle =
addError: (error) ->
$('#page-alert').append error
clearError: ->
$('#page-alert').find('button').nextAll().remove()
showError: ->
$('#page-alert').show()
hideError: ->
$('#page-alert').hide()
$.fn.checkAndRequest = (url, opts, callback, errorHandle) ->
defaults = {}
opts = $.extend defaults, opts
@@ -41,4 +54,5 @@ $ ->
url: url
method: 'post'
data: data
success: callback
success: callback
error: errorHandle

View File

@@ -1,9 +1,7 @@
$ ->
$('.signup-form').find('button').on 'click', (e) ->
e.preventDefault()
$('.signup-form').checkAndRequest '/user/signup',(reply)->
console.log reply
,
$('.signup-form').checkAndRequest '/user/signup/',
username:
check: /^[0-9a-z_]+$/
error: '用户名必须以数字或小写字母开头'
@@ -14,3 +12,11 @@ $ ->
check: ->
$('#passwd').val() is $('#passwd2').val()
error: '两次密码不一致'
, (reply) ->
location.href = '/'
, (reply) ->
if reply.status is 400
error = reply.responseJSON.error
pageErrorHandle.addError error
pageErrorHandle.clearError()
pageErrorHandle.showError()