The following is an encapsulated processing function, which is very convenient to use:
The file name is: jQuery.ajaxRequest.js .
Usage:
var _ajax = {
request: function(o){
var tform = $(o).parents('form');
_ar2(tform,'','_ajax._fb_request' );
},
_fb._request: function(d){
d = eval('(' unescape(d) ')');
if(d.notification){
if(d.type == 'ok'){
alert('Submission successful');
}else if(d.type == 'error '){
alert('Submission failed'); 🎜>
The ajax file code:
Copy the code
url = url || '';
method = method || methods || 'GET';
params = param ? param : params;
jQuery.ajax({
type: method,url:url,data:params,
beforeSend: function(){
//jQuery.jGrowl('数据读取中 请稍候..', { header: '提示', theme: 'blue'});
},
success: function(data) {
//data = jQuery.trim(data).replace(/[ntr]/gi,'');
if(feedback){
eval(feedback '('' escape(data) '')');
return;
}else{
if(data){
if(target){
jQuery(target).html(data);
jQuery.jGrowl('页面请求完毕.', { header: '提示', theme: 'green', 'life': 100});
return;
}
}else{
lg('no feedback');
jQuery.jGrowl('服务器无返回信息.', { header: '提示', theme: 'blue'});
return;
}
}
jQuery.jGrowl(data, { header: '提示', theme: 'blue'});
},
error: function (e){
var s = e.status;
switch(s) {
case 404:
jQuery.jGrowl('请求的页面无法找到. 请联系系统管理员.', { header: '提示', theme: 'blue'});
break;
case 500:
jQuery.jGrowl('服务器错误[500]. 请联系系统管理员.', { header: '提示', theme: 'blue'});
break;
default:
//log('unknow error');
lg(s);
jQuery.jGrowl('未知错误. 请联系系统管理员.', { header: '提示', theme: 'blue'});
}
}
});
}