jQuery.ajaxSetup()
阿新 • • 發佈:2019-05-13
== indexof localhost 校驗 ext url his 判斷 char
jQuery中AJAX請求的默認設置選項。之後執行的所有AJAX請求,如果對應的選項參數沒有設置,將使用更改後的默認設置。
該函數屬於全局jQuery
對象。
/** * ajax初始化 */ jQuery.ajaxSetup({ type: "post", dataType: "json", cache: false, box_obj: null, scroll: null, beforeSend: function (request) { //需要登錄校驗,且用戶未登錄 if(this.login && !istrsidssdssotoken()) { // request.abort(); // jumpToLoginPage(); } //csrf校驗 if (this.csrf) { var crm = Math.random(); //判斷語句,用於本地測試,請勿提交測試或生產 if (window.location.host.indexOf(‘localhost‘) >= 0) { crm = ‘123‘; }// var urlDomain = this.url. $.cookie(‘crm‘, crm, { ‘path‘: ‘/‘, ‘domain‘: ‘.xxx.com‘ }); if (this.url.indexOf(‘?‘) >= 0) { this.url = this.url + ‘&cch=‘ + crm; } else { this.url = this.url + ‘?cch=‘ + crm; } }//contentType: "application/json; charset=utf-8", if (this.applicationType) { request.setRequestHeader("Content-Type", "application/json; charset=utf-8") } }, success: function (data) {}, complete: function (XMLHttpRequest, textStatus) { //csrf校驗-刪除cookie if (this.csrf) { $.cookie(‘crm‘, null, { ‘path‘: ‘/‘, ‘domain‘: ‘.XXX.com‘ });; } }, error: function (jqXHR, textStatus, errorThrown) { if (this.login && jqXHR.status == 401) { // jumpToLoginPage(); } if (this.error_cb) { this.error_cb(jqXHR, textStatus, errorThrown); } } });
jQuery.ajaxSetup()