Determine whether the url can be accessed normally in js

Determine whether the url can be accessed normally in js

$.ajax({
    
    
        type: 'get',
        cache: false,//true的话会读缓存,第二次的时候得到的是上次访问的结果,而不是重新到服务器获取。false的话会在url后面加一个时间缀,让它跑到服务器获取结果。cache只有GET方式的时候有效。
        url: '', //url地址
        dataType: "jsonp", //跨域采用jsonp方式
        processData: false,//processData 默认为true,当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data,false会序列化。
        timeout:3000,//设置超时 ‘0’:为永不超时,当请求超时后会进入error,可以在error中做超时的处理。
        complete: function (data) {
    
    
            //data.status 请求url地址的状态码,以此来判断url是否有效可以访问。
            if (data.status==200) {
    
                
            } else {
    
    
            }
        },
        error:function (){
    
    
        }
    });

Guess you like

Origin blog.csdn.net/weixin_44067333/article/details/113102116