52,797
社区成员
发帖
与我相关
我的任务
分享
<script>
$('form[target=ajax]').live('submit', function(){
var data = [],
$this = $(this),
self = this,
onajax = window[$this.attr('onajax')],
call = window[$this.attr('call')];
if(typeof call!='function'){
call=function(){}
}
if('function'==typeof onajax){
try{
if(onajax.call(this)===false) return false;
}catch(err){
call.call(self, err);
return false;
}
}
$(':input[name]', this).each(function(){
var $this=$(this),
value=$this.data('value'),
name=$this.attr('name');
if($this.is(':radio, :checkbox') && this.checked==false) return true;
if(value===undefined) value=this.value;
data.push({name:name, value:value});
});
$.ajax({
url:$this.attr('action'),
async:true,
data:data,
type:$this.attr('method')||'get',
dataType:$this.attr('dataType')||'json',
headers:{"x-form-call":1},
error:function(xhr, textStatus, errorThrown){
call.call(self, errorThrown||textStatus);
},
success:function(data, textStatus, xhr, headers){
var errorMessage=xhr.getResponseHeader('X-Error-Message');
if(errorMessage){
call.call(self, decodeURIComponent(errorMessage), data);
}else{
call.call(self, null, data);
}
}
});
return false;
});
function toCash(err, data){
if(err){
$.alert(err)
$("#vcode").trigger("click");
}else{
$(':password').val('');
$('input[name=amount]').val('');
$('.recharege-leibie').html(data);
}
}
</script>
============
<?php
if(!$_POST) throw new Exception('参数出错');
$this->display('index.php');
?>
<form action="" method="post" target="ajax" onajax="checkRecharge" call="toCash" dataType="html">
<input type="text" name="vcode" value="1234">
<input type="submit" name="submit" value="提交">
</form>