renamed "on_succes" option to "done" allowing multiple inputs
renamed "on_succes" option to "done" allowing multiple inputs,code refactoring
This commit is contained in:
@@ -40,6 +40,10 @@
|
|||||||
},
|
},
|
||||||
ajax: function (u, s, t, options) {
|
ajax: function (u, s, t, options) {
|
||||||
/*simple ajax function*/
|
/*simple ajax function*/
|
||||||
|
|
||||||
|
// set options default value
|
||||||
|
options = typeof options !== 'undefined' ? options : {};
|
||||||
|
|
||||||
var query = '';
|
var query = '';
|
||||||
if (typeof s == 'string') {
|
if (typeof s == 'string') {
|
||||||
var d = $(s).serialize();
|
var d = $(s).serialize();
|
||||||
@@ -60,30 +64,39 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// default options for jquery ajax function
|
// default success action
|
||||||
|
var success_function = function (msg) {
|
||||||
|
if (t) {
|
||||||
|
if (t == ':eval') eval(msg);
|
||||||
|
else if (typeof t == 'string') $('#' + t).html(msg);
|
||||||
|
else t(msg);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// declare success actions as array
|
||||||
|
var success = [success_function];
|
||||||
|
|
||||||
|
// add user success actions
|
||||||
|
if ($.isArray(options.done)){
|
||||||
|
success = $.merge(success, options.done);
|
||||||
|
} else {
|
||||||
|
success.push(options.done);
|
||||||
|
}
|
||||||
|
|
||||||
|
// default jquery ajax options
|
||||||
var ajax_options = {
|
var ajax_options = {
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: u,
|
url: u,
|
||||||
data: query,
|
data: query,
|
||||||
success: function (msg) {
|
success: success
|
||||||
if (t) {
|
|
||||||
if (t == ':eval') eval(msg);
|
|
||||||
else if (typeof t == 'string') $('#' + t).html(msg);
|
|
||||||
else t(msg);
|
|
||||||
}
|
|
||||||
// trigger on_success
|
|
||||||
if (options.on_success){
|
|
||||||
options.on_success();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//remove custom "done" option if exists
|
||||||
|
delete options.done;
|
||||||
|
|
||||||
// merge default ajax options with user custom options
|
// merge default ajax options with user custom options
|
||||||
for (var attrname in options) {
|
for (var attrname in options) {
|
||||||
// not merge custom on_success option
|
|
||||||
if(attrname != "on_success"){
|
|
||||||
ajax_options[attrname] = options[attrname];
|
ajax_options[attrname] = options[attrname];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// call ajax function
|
// call ajax function
|
||||||
|
|||||||
@@ -40,6 +40,10 @@
|
|||||||
},
|
},
|
||||||
ajax: function (u, s, t, options) {
|
ajax: function (u, s, t, options) {
|
||||||
/*simple ajax function*/
|
/*simple ajax function*/
|
||||||
|
|
||||||
|
// set options default value
|
||||||
|
options = typeof options !== 'undefined' ? options : {};
|
||||||
|
|
||||||
var query = '';
|
var query = '';
|
||||||
if (typeof s == 'string') {
|
if (typeof s == 'string') {
|
||||||
var d = $(s).serialize();
|
var d = $(s).serialize();
|
||||||
@@ -60,30 +64,39 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// default options for jquery ajax function
|
// default success action
|
||||||
|
var success_function = function (msg) {
|
||||||
|
if (t) {
|
||||||
|
if (t == ':eval') eval(msg);
|
||||||
|
else if (typeof t == 'string') $('#' + t).html(msg);
|
||||||
|
else t(msg);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// declare success actions as array
|
||||||
|
var success = [success_function];
|
||||||
|
|
||||||
|
// add user success actions
|
||||||
|
if ($.isArray(options.done)){
|
||||||
|
success = $.merge(success, options.done);
|
||||||
|
} else {
|
||||||
|
success.push(options.done);
|
||||||
|
}
|
||||||
|
|
||||||
|
// default jquery ajax options
|
||||||
var ajax_options = {
|
var ajax_options = {
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: u,
|
url: u,
|
||||||
data: query,
|
data: query,
|
||||||
success: function (msg) {
|
success: success
|
||||||
if (t) {
|
|
||||||
if (t == ':eval') eval(msg);
|
|
||||||
else if (typeof t == 'string') $('#' + t).html(msg);
|
|
||||||
else t(msg);
|
|
||||||
}
|
|
||||||
// trigger on_success
|
|
||||||
if (options.on_success){
|
|
||||||
options.on_success();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//remove custom "done" option if exists
|
||||||
|
delete options.done;
|
||||||
|
|
||||||
// merge default ajax options with user custom options
|
// merge default ajax options with user custom options
|
||||||
for (var attrname in options) {
|
for (var attrname in options) {
|
||||||
// not merge custom on_success option
|
|
||||||
if(attrname != "on_success"){
|
|
||||||
ajax_options[attrname] = options[attrname];
|
ajax_options[attrname] = options[attrname];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// call ajax function
|
// call ajax function
|
||||||
|
|||||||
@@ -40,6 +40,10 @@
|
|||||||
},
|
},
|
||||||
ajax: function (u, s, t, options) {
|
ajax: function (u, s, t, options) {
|
||||||
/*simple ajax function*/
|
/*simple ajax function*/
|
||||||
|
|
||||||
|
// set options default value
|
||||||
|
options = typeof options !== 'undefined' ? options : {};
|
||||||
|
|
||||||
var query = '';
|
var query = '';
|
||||||
if (typeof s == 'string') {
|
if (typeof s == 'string') {
|
||||||
var d = $(s).serialize();
|
var d = $(s).serialize();
|
||||||
@@ -60,30 +64,39 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// default options for jquery ajax function
|
// default success action
|
||||||
|
var success_function = function (msg) {
|
||||||
|
if (t) {
|
||||||
|
if (t == ':eval') eval(msg);
|
||||||
|
else if (typeof t == 'string') $('#' + t).html(msg);
|
||||||
|
else t(msg);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// declare success actions as array
|
||||||
|
var success = [success_function];
|
||||||
|
|
||||||
|
// add user success actions
|
||||||
|
if ($.isArray(options.done)){
|
||||||
|
success = $.merge(success, options.done);
|
||||||
|
} else {
|
||||||
|
success.push(options.done);
|
||||||
|
}
|
||||||
|
|
||||||
|
// default jquery ajax options
|
||||||
var ajax_options = {
|
var ajax_options = {
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: u,
|
url: u,
|
||||||
data: query,
|
data: query,
|
||||||
success: function (msg) {
|
success: success
|
||||||
if (t) {
|
|
||||||
if (t == ':eval') eval(msg);
|
|
||||||
else if (typeof t == 'string') $('#' + t).html(msg);
|
|
||||||
else t(msg);
|
|
||||||
}
|
|
||||||
// trigger on_success
|
|
||||||
if (options.on_success){
|
|
||||||
options.on_success();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//remove custom "done" option if exists
|
||||||
|
delete options.done;
|
||||||
|
|
||||||
// merge default ajax options with user custom options
|
// merge default ajax options with user custom options
|
||||||
for (var attrname in options) {
|
for (var attrname in options) {
|
||||||
// not merge custom on_success option
|
|
||||||
if(attrname != "on_success"){
|
|
||||||
ajax_options[attrname] = options[attrname];
|
ajax_options[attrname] = options[attrname];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// call ajax function
|
// call ajax function
|
||||||
|
|||||||
Reference in New Issue
Block a user