结合tp封装的ajax方法

2017-11-03 07:59:54来源:CSDN作者:longzai89757人点击

分享
结合tp封装的ajax方法   //ajax get请求    $('.ajax-get').click(function(){       vartarget;       varthat =this;       if( $(this).hasClass('confirm') ) {           if(!confirm('确认要执行该操作吗?')){               returnfalse;            }        }       if( (target = $(this).attr('href')) || (target = $(this).attr('url')) ) {            $.get(target).success(function(data){               if(data.status==1) {                   if(data.url) {                        updateAlert(data.info +' 页面即将自动跳转~','alert-success');                    }else{                        updateAlert(data.info,'alert-success');                    }                    setTimeout(function(){                       if(data.url) {                            location.href=data.url;                        }elseif( $(that).hasClass('no-refresh')){                            $('#top-alert').find('button').click();                        }else{                            location.reload();                        }                    },1500);                }else{                    updateAlert(data.info);                    setTimeout(function(){                       if(data.url) {                            location.href=data.url;                        }else{                            $('#top-alert').find('button').click();                        }                    },1500);                }            });        }       returnfalse;    });   //ajax post submit请求    $('.ajax-post').click(function(){       vartarget,query,form;       vartarget_form = $(this).attr('target-form');       varthat =this;              varnead_confirm=false;       if( ($(this).attr('type')=='submit') || (target = $(this).attr('href')) || (target = $(this).attr('url')) ){            form = $('.'+target_form);           if($(this).attr('hide-data') === 'true'){//无数据时也可以使用的功能             form = $('.hide-data');             query = form.serialize();            }elseif(form.get(0)==undefined){             returnfalse;            }elseif( form.get(0).nodeName=='FORM'){               if( $(this).hasClass('confirm') ) {                   if(!confirm('确认要执行该操作吗?')){                       returnfalse;                    }                }               if($(this).attr('url') !== undefined){                 target = $(this).attr('url');                }else{                 target = form.get(0).action;                }                query = form.serialize();            }elseif( form.get(0).nodeName=='INPUT'|| form.get(0).nodeName=='SELECT'|| form.get(0).nodeName=='TEXTAREA') {                form.each(function(k,v){                   if(v.type=='checkbox'&& v.checked==true){                        nead_confirm =true;                    }                })               if( nead_confirm && $(this).hasClass('confirm') ) {                   if(!confirm('确认要执行该操作吗?')){                       returnfalse;                    }                }                query = form.serialize();            }else{               if( $(this).hasClass('confirm') ) {                   if(!confirm('确认要执行该操作吗?')){                       returnfalse;                    }                }                query = form.find('input,select,textarea').serialize();            }           //console.log(target);return;            $(that).addClass('disabled').attr('autocomplete','off').prop('disabled',true);            $.post(target,query).success(function(data){                            if(data.status==1) {                   if(data.url) {                        updateAlert(data.info +' 页面即将跳转~','alert-success');                    }else{                        updateAlert(data.info ,'alert-success');                    }                    setTimeout(function(){                       if(data.url) {                            location.href=data.url;                        }elseif( $(that).hasClass('no-refresh')){                            $('#top-alert').find('button').click();                            $(that).removeClass('disabled').prop('disabled',false);                        }else{                            location.reload();                        }                    },1500);                }else{                                     updateAlert(data.info);                    setTimeout(function(){                       if(data.url) {                            location.href=data.url;                        }else{                            $('#top-alert').find('button').click();                            $(that).removeClass('disabled').prop('disabled',false);                        }                    },1500);                }            });        }       returnfalse;    });

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台