//簡(jiǎn)單的ajax表單提交(function($,window,undefined){varajaxForm=function(opts){vardef={successLabel:'發(fā)送成功',url:'/user/check',dataType:'html'}this.form=$('#'+formid)||$('form');this.opts=$.extend({},def,opts);this.formdata=this.form.serialize();}//發(fā)送前執(zhí)行ajaxForm.prototype.before=function(){this.submitButton=$form.find(':submit');this.submitButton.val('提交中...');}//請(qǐng)求成功回執(zhí)函數(shù)ajaxForm.prototype.success=function(data){$('#message')=this.opts.successLabel;}//ajaxForm.prototype.send=function(){$.ajax({url:this.opts.url,//無錯(cuò)before:this.before,//引用ajaxForm.before方法success:this.success,//執(zhí)行到這里錯(cuò)誤,success內(nèi)部this方法出錯(cuò)了type:'post',data:this.formdata})}window.ajaxForm=ajaxForm;})(jQuery,window)//實(shí)例newajaxForm().send();以上執(zhí)行,會(huì)提示this.opts.successLabel未定義,我知道當(dāng)ajax引用this.success的時(shí)候,success內(nèi)部this已經(jīng)指向當(dāng)前ajax對(duì)象了,請(qǐng)問各位老師,如何在ajax方法中,正確引用一個(gè)原型的方法呢?
怎樣在jquery.ajax中執(zhí)行當(dāng)前函數(shù)的其他方法?
慕運(yùn)維8079593
2019-03-29 22:09:18