Xgoajax Introduction
Uniform processing of the results of AJAX requests, including message prompts, error handling, and so on, ensures that our project has a unified style and simplifies a lot of code.
Project Address: Https://github.com/xucongli1989/XGoAjax
Download Address: https://github.com/xucongli1989/XGoAjax/releases use scene Ajax callback information to prompt response processing, such as prompt success or failure, and other messages. The Submit button requires multiple AJAX request attributes to be blocked in the AJAX request (prevent multiple submissions)
plug-in Global settings:
Property name |
Default value |
Description |
TemplateName |
"Default" |
Default template Name |
Isexclusive |
True |
Exclusive Request |
Plug-in options:
Property name |
Default value |
Description |
Id |
“” |
The identity of the initiating request is optionally specified, primarily to make it easier to determine that the request is the same type of operation. For example, a form submit button triggers a situation or a group of AJAX requests, we can specify the ID to identify the user's request to click the Submit button, so that if it is in exclusive mode, the plugin will pass this ID to determine if the last request has been completed, and if not, no processing. If it is finished, you can restart the request again. The advantage of doing this is to prevent users from clicking the Submit button more than once in a short period of time. (The old practice is to disable this button at the time of the request.) Note: If unspecified, the default is greedy mode, and a valid value must be specified when the request is exclusive. |
TemplateName |
The TemplateName property in global settings. "Default" if not specified; |
Specifies the template used for the processing of the resulting message |
Templateoption |
{} |
Template customization options, which are completely customized by the user as needed in different templates, please refer to "template options" in detail |
Isexclusive |
Isexclusive Property in Global settings |
True: An exclusive request, in order to initiate the same request, must wait for the last request to end; false: greedy request, without limiting duplicate requests. |
Ajax |
[] |
$.ajax option, each item of the array represents an AJAX request and can have multiple AJAX requests. If there is only one request, you can use the {...} without the array. Alternative. If this parameter is not passed or the array item length is 0, the default AJAX behavior is used. The default values refer to the AJAX default options. |
Target |
Null |
An object that initiates an event, primarily to facilitate locking of the object. |
Targetoption |
{} |
Target customization options |
Prebefore |
Null |
Executes before before and, if returned Fase, no longer performs before subsequent operations and terminates this AJAX request |
Before |
Null |
Ajax request function, if unspecified, executes the before function in the template and, if returned Fase, no longer performs before subsequent operations and terminates this AJAX request |
Postbefore |
Null |
Executes after before and, if returned Fase, terminates this AJAX request |
Presuccess |
Null |
Executes before success, and if Fase is returned, subsequent operations of success are no longer performed |
Success |
Null |
After Ajax success function, if unspecified, executes the success function in the template and, if returned Fase, no longer performs success subsequent operations |
Postsuccess |
Null |
Execute after success |
Precomplete |
Null |
Executes before complete, and if Fase is returned, subsequent operations of complete are no longer performed |
Complete |
Null |
function when Ajax completes, and if unspecified, executes the complete function in the template and, if returned Fase, no longer performs complete subsequent operations |
Postcomplete |
Null |
Execute after complete |
Preerror |
Null |
Executes before the error, and if Fase is returned, the subsequent operation of the error is no longer performed |
Error |
Null |
function after Ajax failure, and if not specified, the error function in the template is executed, and if Fase is returned, subsequent operation of the error is no longer performed |
Posterror |
Null |
After the error is performed |
Template options:
Property name |
Default value |
Description |
Name |
|
Template Name |
Before |
function (OPS) |
If False is returned before the request, the subsequent execution is blocked. OPS: Current Plug-in options |
Error |
function (OPS) |
The function that was executed after the failure. OPS: Current Plug-in options |
Success |
function (OPS, datas) |
Executes after success, datas an array or object. OPS: Current Plug-in options Datas: Requests the returned data, if there are more than one Ajax request, the array, otherwise directly to the output object value. |
Complete |
function (OPS) |
Execute after completion. OPS: Current Plug-in options |
Templateoption |
{} |
Template customization Options |
ajax default options:
Property name |
Default value |
Description |
Url |
If not specified, the action for the first form, or location.href if it has not been specified; |
Ajax Request Path |
DataType |
"JSON" |
Data format |
Type |
"Get" |
Request method |
Data |
First form serialization value (Serialize () method of jquery) |
The data sent |
Method
Method name |
Description |
$. Xgoajax.addtemplate (model) |
Add a new template to the plugin, model please refer to "Template options" |
$. Xgoajax.getajaxlist () |
Get the Ajax object that is currently being processed |
$. Xgoajax.gettemplate (name) |
Get template object based on template name |
$. Xgoajax.globalsettings ({...}) |
This plugin global setting, can set templatename, mode ... |
$. Xgoajax.getglobalsettings () |
Get this plugin global settings |
Basic usage Examples
/************** Default Template: *******************///Each Click Emits an AJAX request (currently must have only one request, exclusive mode) $ ("#btnSave1"). On ("CLI CK ", function () {$.
Xgoajax ({id: "btnSave1", Ajax: {URL: "Data.aspx"}});
}); Each click Emits an AJAX request (can emit multiple requests, greedy mode) $ ("#btnSave2"). On ("click", Function () {$.
Xgoajax ({isexclusive:false, Ajax: {URL: "Data.aspx"}});
}); Each click Emits multiple AJAX requests (currently must have only one set of requests, exclusive mode) $ ("#btnSave3"). On ("click", Function () {$. Xgoajax ({id: "BtnSave3", Ajax: [{type: ' Get ', ur
L: "Data.aspx"}, {type: "post", url: "Data.aspx"
}]
});
}); Each click Emits multiple AJAX requests (can emit multiple sets of requests, greedy mode) $ ("#btnSave4"). On ("click", Function () {$.
Xgoajax ({ Isexclusive:false, Ajax: [{type: ' Get ', url: ' data.aspx '
}, {type: ' post ', url: ' Data.aspx '}]};
}); /**************artdialog Template: *******************///Per click to issue an AJAX request (currently must have only one request, exclusive mode) $ ("#btnSaveArtdialog1") . On ("click", Function () {$. Xgoajax ({templatename: "Artdialog", ID: "BtnSaveArtdialog1", Ajax: {URL:
"Data.aspx"});
}); Each click Emits an AJAX request (can emit multiple requests, greedy mode) $ ("#btnSaveArtdialog2"). On ("click", Function () {$. Xgoajax ({templatename: "Artdialog", Isexclusive:false, Ajax: {url: "Dat
A.aspx "}});
}); Each click Emits an AJAX request (can emit multiple requests, greedy mode) $ ("#btnSaveArtdialog3"). On ("click", Function () {$.
Xgoajax ({ TemplateName: "Artdialog", ID: "BtnSaveArtdialog3", Ajax: [{type: "Get", url: "Data.aspx"}, {type: "post", ur
L: "Data.aspx"});
}); Each click Emits multiple AJAX requests (can emit multiple sets of requests, greedy mode) $ ("#btnSaveArtdialog4"). On ("click", Function () {$.
Xgoajax ({templatename: "Artdialog", Isexclusive:false, Ajax: [{
Type: ' Get ', url: ' data.aspx '}, {type: ' Post ',
URL: "Data.aspx"}]});
});
/****************** Event ***********************///All Events (Basic) $ ("#btnSaveWithEvent"). On ("click", Function () {
var _this = this; $. Xgoajax ({id: "Btnsavewithevent", Ajax: {url: "daTa.aspx "}, Prebefore:function () {Console.log (" Prebefore ");
}, Postbefore:function () {Console.log ("Postbefore");
}, Presuccess:function () {Console.log ("presuccess");
}, Postsuccess:function () {Console.log ("postsuccess");
}, Precomplete:function () {Console.log ("Precomplete");
}, Postcomplete:function () {Console.log ("Postcomplete");
}, Preerror:function () {Console.log ("Preerror");
}, Posterror:function () {Console.log ("Posterror");
}
});
}); Before returns false $ ("#btnSaveWithEvent1"). On ("click", Function () {$. Xgoajax ({id: "BtnSaveWithEvent1", Ajax: {URL: "Data.aspx"}, Prebefore:
function () {Console.log ("Prebefore");
return false;
}, Postbefore:function () {Console.log ("Postbefore");
}, Presuccess:function () {Console.log ("presuccess");
}, Postsuccess:function () {Console.log ("postsuccess");
}, Precomplete:function () {Console.log ("Precomplete");
}, Postcomplete:function () {Console.log ("Postcomplete");
}, Preerror:function () {Console.log ("Preerror");
}, Posterror:function () {Console.log ("Posterror");
} });
});
Specify target to disable button $ ("#btnSaveWithEvent2") in the request. On ("click", Function () {var _this = this; $.
Xgoajax ({templatename: "Artdialog", Target: _this, Isexclusive:false,
ID: "BtnSaveWithEvent2", Ajax: {URL: "Data.aspx"}});
});
specific demo Please see the source code: xgoajax\web\index.html Event Call Flowchart