前端Ajax使用标准格式(jQuery)

<script type="text/javascript">
	window.onload = function () {//页面刷新即加载
    $.ajax({
        url:'http://10.0.19.21:8080/findall',
        type:'GET', //GET    POST
        async:true,    //或false,是否异步
        timeout:5000,    //超时时间
        dataType:'json',    //返回的数据格式:json/xml/html/script/jsonp/text

        beforeSend:function(xhr){//请求发送之前进行的操作
            console.log(xhr)
            console.log('发送前')
        },
        success:function(data,textStatus,jqXHR){//请求成功之后的返回结果
            console.log(data);
        },
        error:function(xhr,textStatus){//请求失败之后的返回错误信息
            console.log('错误',xhr.responseText);
            console.log(xhr);
            console.log(textStatus);
        }
    })


}
</script>
发布了15 篇原创文章 · 获赞 0 · 访问量 1252

猜你喜欢

转载自blog.csdn.net/weixin_42656358/article/details/104745512