When the project framework is built, it writes the public interface of the AJAX submission, which is the error message that wants to unify the log and handle the Ajax return.
Today, but also to help me solve another problem: each time you open a page, there is an AJAX request will always call two times, so open the Chrome debugger, where the public Ajax submitted a breakpoint, view Chrome's call Stack, it is easy to find the source of two calls, Problem solved instantaneously.
Stick to my util.js:
/*! * Front-end JS Common method plugin * Copyright 2011-2015 zhangjh. * Licensed under MIT (https://github.com/firebata/skysport/blob/master/ LICENSE)*/(function ($) { "Use Strict"; //Extending common methods$.extend ({sendrestfulajax:sendrestfulajax,//AjaxSendjsonajax:sendjsonajax, Strtojson:strtojson,//& connect string to JSON objectStrisempty:strisempty,//determine if the string is emptyStrisnotempty:strisnotempty//judge string is not empty }); /** * * * @param _url path * @param _data Data * @param _type http method * @param _datatype data type * @param _dosuccess Successful callback function*/ functionSendrestfulajax (_url, _data, _type, _datatype, _dosuccess) {varType = Strisempty (_type)? ' POST ': _type; //var dataType = _type = = "undefined" | | $.trim (_datatype) = = "? ' JSON ': _datatype; varSF = Strisempty (_dosuccess)?dosucess: _dosuccess; $.ajax ({URL: _url, data: _data, Type:type,//Datatype:datatype,success:sf, error:donotsucess}); } /** * * * @param _url path * @param _data Data * @param _type http method * @param _datatype data type * @param _dosuccess Successful callback function*/ functionSendjsonajax (_url, _data, _dosuccess) {varSF = Strisempty (_dosuccess)?dosucess: _dosuccess; $.ajax ({url: _url, data:JSON.stringify (_data), type:"POST", DataType:"JSON", ContentType:"Application/json", SUCCESS:SF, error:donotsucess}); } /*Bootbox.setlocale ("ZH_CN");*/ varDonotsucess =function(XMLHttpRequest, Textstatus, Errorthrown) {//Console.error (XMLHttpRequest);Bootbox.alert ("This operation failed.")); } varDosucess =function(XMLHttpRequest, Textstatus, Errorthrown) {//Bootbox.alert (XMLHttpRequest); } /** * Convert the "&" concatenated string to JSON * @param str "&" concatenated String * @returns {Object} Json*/ functionStrtojson (str) {str= Str.replace (/&/g, "', '"); STR= Str.replace (/=/g, "': '")); STR= "({'" + str + "'})"; varobj =eval (str); returnobj; } /** * Check string is empty * @param input String * @returns {Boolean}*/ functionStrisempty (input) {returnInput = = Undefined | | $.trim (input) = = " } /** * Check string is not empty * @param input String * @returns {Boolean}*/ functionStrisnotempty (input) {return!strisempty (input); }} (JQuery));
A great use of the public interface for AJAX submissions