加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax设置默认值 ajaxSetup

发布时间:2020-12-16 01:32:27 所属栏目:百科 来源:网络整理
导读:jQuery ajaxSetup() 方法 $(function(){ // 设置jQuery Ajax全局的参数 $.ajaxSetup({ type: "POST",async: false,cache: false,dataType: "JSON",error: function(jqXHR,textStatus,errorThrown){ switch (jqXHR.status){ case(500): alert("服务器系统内部

jQuery ajaxSetup() 方法

$(function(){  
    // 设置jQuery Ajax全局的参数  
    $.ajaxSetup({  
        type: "POST",async: false,cache: false,dataType: "JSON",error: function(jqXHR,textStatus,errorThrown){  
            switch (jqXHR.status){  
                case(500):  
                    alert("服务器系统内部错误");  
                    break;  
                case(401):  
                    alert("未登录");  
                    break;  
                case(403):  
                    alert("无权限执行此操作");  
                    break;  
                case(408):  
                    alert("请求超时");  
                    break;  
                default:  
                    alert("未知错误");  
            }  
        },success: function(data){  
            alert("操作成功");  
        }  
    });  
});

当设置该属性后,在其他jQuery没有设置的ajax中,默认设用该设置。


----------------------------------------------------------------------------------------------------

Cache缓存问题 由于IE的缓存处理机制问题,每次通过XMLHttpRequest访问动态页面返回的总是首次访问的内容,解决方法有: 1. 客户端通过添加随机字符串解决。如: var url = 'http://url/'; url += '?temp=' + new Date().getTime(); url += '?temp=' + Math.random(); 2. 在HTTP headers禁止缓存。如: HTTP: <meta http-equiv="pragma" content="no-cache" /> <meta http-equiv="Cache-Control" content="no-cache,must-revalidate" /> <meta http-equiv="expires" content="Thu,01 Jan 1970 00:00:01 GMT" /> <meta http-equiv="expires" content="0" /> PHP: header("Expires: Thu,01 Jan 1970 00:00:01 GMT"); header("Cache-Control: no-cache,must-revalidate"); header("Pragma: no-cache"); ASP: Response.expires=0 Response.addHeader("pragma","no-cache") Response.addHeader("Cache-Control","no-cache,must-revalidate") JSP: response.addHeader("Cache-Control","no-cache"); response.addHeader("Expires","Thu,01 Jan 1970 00:00:01 GMT"); 3. 在XMLHttpRequest发送请求之前加上: XMLHttpRequest.setRequestHeader("If-Modified-Since","0"); XMLHttpRequest.send(null);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读