/** * Created by Mai on 2017/4/20. */ var CommonAjax = { post: function (url, data, successCallback, errorCallback) { $.ajax({ type:"POST", url: url, data: {'data': JSON.stringify(data)}, dataType: 'json', cache: false, timeout: 50000, success: function(result){ if (result.error === 0) { if (successCallback) { successCallback(result.data); } } else { alert('error: ' + result.message); if (errorCallback) { errorCallback(); } } }, error: function(jqXHR, textStatus, errorThrown){ alert('url: ' + url +' error ' + textStatus + " " + errorThrown); if (errorCallback) { errorCallback(); } } }); }, postRationLib: function (url, data, successCallback, errorCallback) { $.ajax({ type:"POST", url: url, data: data, dataType: 'json', cache: false, timeout: 50000, success: function(result){ if (!result.error) { if (successCallback) { successCallback(result.data); } } else { alert('error: ' + result.message); if (errorCallback) { errorCallback(); } } }, error: function(jqXHR, textStatus, errorThrown){ alert('error ' + textStatus + " " + errorThrown); if (errorCallback) { errorCallback(); } } }); }, postEx: function(url, params, dftTimeOutMilSec, successCallback, failCallback, exceptionCallback){ $.ajax({ type:"POST", url: url, data: {'params': JSON.stringify(params)}, dataType: 'json', cache: false, timeout: dftTimeOutMilSec, success: function(result){ if (result.error) { if (successCallback) { successCallback(result.data); } } else { alert('error: ' + result.message); if (failCallback) { failCallback(); } } }, error: function(jqXHR, textStatus, errorThrown){ alert('url: ' + url +' error ' + textStatus + " " + errorThrown); if (exceptionCallback) { exceptionCallback(); } } }); } };