/** * */ //Logout button click event var urls = { "/rpcnew/requestNewPassword" : "yes", "/rpcnew/createFreeAcc" : "yes", "/rpcnew/createPaidAcc" : "yes", "/rpcnew/validateEmail" : "yes", "/rpcnew/sendFeedback" : "yes", "/rpcnew/changePwdFromLink" : "yes", "/rpcnew/validate" : "yes", "/rpcnew/updateProfile" : "yes", "/rpcnew/continueUpg" : "yes", "/rpcnew/applypendingcharges" : "yes", "/rpcnew/changePassword" : "yes", "/rpcnew/cancel" : "yes", "/rpcnew/updatehosts" : "yes", "/rpcnew/updatecc" : "yes", "/rpcnew/getHostsInfo" : "yes", "/rpcnew/createOfferPaidAcc" : "yes", "/rpcnew/getWebAccessToken" : "yes", }; jQuery.fn.makeRequest = function (method, url, data, dataType, successFunction) { var csTkn = ""; try{ if(typeof(urls[url]) !="undefined" && urls[url] == 'yes'){ $.ajax ({ type : "POST", // Ex: 'POST' or 'GET' url : "/rpcnew/getCSRFToken", // Ex: 'home/filelist.html' data : "", async : false, success : function(pdata){ csTkn = pdata.csrf; makeRequestWithToken(method, null, url, data, dataType, successFunction, csTkn); } }); } else { makeRequestWithToken(method, null, url, data, dataType, successFunction,""); } /*$.ajax ({ type : method, // Ex: 'POST' or 'GET' url : url, // Ex: 'home/filelist.html' data : data, // Ex: {path:'/'} dataType : dataType, // Type of response from Server eg: json, xml etc. success : successFunction, // The call back function to be called on success. error : failureFunction });*/ } catch(e) { }; }; function makeRequestWithToken(method, contentType, url, data, dataType, successFunction, tkn){ if(tkn != "") { if (contentType == null && dataType != null){ $.ajax ({ type : method, // Ex: 'POST' or 'GET' url : url, // Ex: 'home/filelist.html' data : data, // Ex: {path:'/'} headers: {csrftoken: tkn}, dataType : dataType, // Type of response from Server eg: json, xml etc. success : successFunction, // The call back function to be called on success. error : failureFunction }); } else { $.ajax ({ type : method, // Ex: 'POST' or 'GET' contentType: contentType, url: url, data: data, // Type of response from Server eg: json, xml etc. headers: {csrftoken: tkn}, success : successFunction, // The call back function to be called on success. error : failureFunction }); } } else{ if (contentType == null && dataType != null){ $.ajax ({ type : method, // Ex: 'POST' or 'GET' url : url, // Ex: 'home/filelist.html' data : data, // Ex: {path:'/'} dataType : dataType, // Type of response from Server eg: json, xml etc. success : successFunction, // The call back function to be called on success. error : failureFunction }); } else { $.ajax ({ type : method, // Ex: 'POST' or 'GET' contentType: contentType, url: url, data: data, // Type of response from Server eg: json, xml etc. success : successFunction, // The call back function to be called on success. error : failureFunction }); } } } function failureFunction(response){ }