MooTools 异步请求验证

http://www.chinamootools.com/

问题 MooTools 异步请求例子

<{foreach from=array('0','1','2','3','4') item=cat_f key='key'}>
<tr>
<th><em class="red">*</em><{t}>名称:<{/t}></th>
<td><{input type="text" name="cat_f[{$key}][cat_name]"
onchange="nameCheck(this)" size="20" vtype="required"}>
<span></span>
</td>
</tr>
<{/foreach}>

<form method="post" action="index.php?app=tfsh&amp;ctl=admin_cat&amp;act=save" id="add_form">
<div class="tableform">
<div class="division">
<table cellpadding="0" cellspacing="0" border="0">
<input type="hidden" value="add_f" name="add_f">
<tbody><tr>
<th><em class="red">*</em>名称:</th>
<td><input class="x-input" type="text" name="cat_f[0][cat_name]" onchange="nameCheck(this)" size="20" vtype="required" id="dom_el_3742f70"> <span></span>
</td>
</tr>
<tr>
<th><em class="red">*</em>名称:</th>
<td><input class="x-input" type="text" name="cat_f[1][cat_name]" onchange="nameCheck(this)" size="20" vtype="required" id="dom_el_3742f71"> <span></span>
</td>
</tr>
<tr>
<th><em class="red">*</em>名称:</th>
<td><input class="x-input" type="text" name="cat_f[2][cat_name]" onchange="nameCheck(this)" size="20" vtype="required" id="dom_el_3742f72"> <span></span>
</td>
</tr>
<tr>
<th><em class="red">*</em>名称:</th>
<td><input class="x-input" type="text" name="cat_f[3][cat_name]" onchange="nameCheck(this)" size="20" vtype="required" id="dom_el_3742f73"> <span></span>
</td>
</tr>
<tr>
<th><em class="red">*</em>名称:</th>
<td><input class="x-input" type="text" name="cat_f[4][cat_name]" onchange="nameCheck(this)" size="20" vtype="required" id="dom_el_3742f74"> <span></span>
</td>
</tr>
</tbody></table>
</div>
</div>
<div class="table-action">
<button type="submit" id="newmember-edit-form-submit" class="btn"><span><span>保存</span></span></button><button class="btn btn-secondary " isclosedialogbtn="true" onclick="W.page('index.php?app=tfsh&amp;ctl=admin_cat&amp;act=index')" type="button"><span><span>取消</span></span></button>
</div>
</form>
<script>
(function(){
var _form = $('add_form');
var btn =$('newmember-edit-form-submit');
//var finder = finderGroup['Array'];
_form.store('target',{
onComplete:function(){ },
onSuccess:function(response){
var hash_res_obj = JSON.decode(response);
if (hash_res_obj.success != undefined && hash_res_obj.success != "")
{
try{
var _dialogIns = btn.getParent('.dialog').retrieve('instance');
}catch(e){} if(_dialogIns)
{
_dialogIns.close();
finder.refresh.delay(400,finder);
}
}
else
{
//alert(hash_res_obj.error);
}
}
}); btn.addEvent('click',function(){
_form.fireEvent('submit',{stop:$empty}); }); })();
function nameCheck(input){
new Request({
url:'/desktop/index.php?app=tfsh&ctl=admin_cat&act=namecheck',
method:'post',
data:input.name+'='+encodeURIComponent(input.value=input.value.trim()),
onSuccess: function(rs) {
rs = JSON.decode(rs);
if(rs.error) {
input.getNext().innerHTML = '<span class="error caution notice-inline">' +rs.error + '</span>';
}
else if(rs.success) {
input.getNext().innerHTML = '<span class="success notice-inline">' +rs.success + '</span>'; }
}
}).send();
}
</script>
public function namecheck()
{
$checkname = '';
if(!$checkname){
echo json_encode(array('error'=>app::get('tfsh')->_('输入的名称有误,请重新输入')));exit;
}else{
echo json_encode(array('success'=>app::get('tfsh')->_('该名称可用')));exit;
}
}
$this->begin('index.php?app=tfsh&ctl=admin_cat&act=index');
$this->end(true,app::get('tfsh')->_('保存成功'));
$this->end(false,app::get('tfsh')->_('输入的名称有误,请重新输入'));
上一篇:WIN 下的超动态菜单(二)用法


下一篇:web压力测试-pylot