//簡單的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('提交中...');}//請求成功回執(zhí)函數(shù)ajaxForm.prototype.success=function(data){$('#message')=this.opts.successLabel;}//ajaxForm.prototype.send=function(){$.ajax({url:this.opts.url,//無錯before:this.before,//引用ajaxForm.before方法success:this.success,//執(zhí)行到這里錯誤,success內(nèi)部this方法出錯了type:'post',data:this.formdata})}window.ajaxForm=ajaxForm;})(jQuery,window)//實例newajaxForm().send();以上執(zhí)行,會提示this.opts.successLabel未定義,我知道當ajax引用this.success的時候,success內(nèi)部this已經(jīng)指向當前ajax對象了,請問各位老師,如何在ajax方法中,正確引用一個原型的方法呢?
怎樣在jquery.ajax中執(zhí)行當前函數(shù)的其他方法?
慕運維8079593
2019-03-29 22:09:18