[英]universal jquery ajax call function
wondering is there any kind of global (universal) one function for calling ajax function.. for example i have lots of similar call like this:想知道是否有任何一种全局(通用)单一函数来调用 ajax 函数.. 例如,我有很多类似的调用:
$.ajax({
url: some_url_address,
type: 'post',
data: $('#form').serialize(),
dataType: 'html',
success: function(data){
alert('success');
}
});
and i would like to make it something like我想让它像
callAjax('my_url', 'post', {some_data}, 'alert("success")');
and in javascript file:并在 javascript 文件中:
function callAjax(url, type, data, successFunction, errorFunction, beforeFunction){
$.ajax({
url: url,
type: type,
data: data,
dataType: 'html',
beforeSend: function(){
beforeFunction;
},
success: function(){
successFunction;
}
error: function(){
errorFunction;
}
});
}
that in my page from where i'm calling that function it would return results from before, error, success, etc.. :)在我调用该函数的页面中,它将返回之前的结果、错误、成功等。:)
Just install webpack by npm install
.只需通过npm install
安装 webpack。
And in the input field write data-ajaxify='true'
并在输入字段中写入data-ajaxify='true'
Also include the npm js and css file.还包括 npm js 和 css 文件。
<input type='test' data-ajaxify='true' data-url='/someurl' data-method='post'>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.