jquery ajax格式

来源:互联网 发布:unity3d 透明贴图 编辑:程序博客网 时间:2024/04/19 15:50

jquery ajax的请求格式

$.ajax({        type : 'post',//post或者get        url : url,        async : false,//是否异步提交 默认为true        global : false,//阻止ajax全局属性生效,比如下面的ajaxStart和ajaxStop        data : {                "id" : id,                "name" : name,                "title" : title        },//json格式        //data : 'id='+$('#id').val(),//字符串格式        dataType : 'html', //json        success : function(msg){                 //数据处理        },        error : function(msg){                console.log(msg);//输出报错信息        } });

ajax请求发起和完成时调用的方法,ajax请求发起时,显示遮罩层,请求完成后,关闭遮罩层

<div id="ajaxShowBg" style="width: 100%; height: 100%; position: fixed; z-index: 1988; top: 0; left: 0; overflow: hidden; display: none;">    <div style="height: 100%; text-align: center; opacity: 0.5; background: #ECE8DE; padding-top: 20%;">        <div style="">            <img src="/images/loading3.gif"/>        </div>    </div></div><script>    $(function(){        // jquery 1.8以上只能绑定在document上,这里需要注意下        $(document).ajaxStart(function(){            $("#ajaxShowBg").show();        }).ajaxStop(function(){            $("#ajaxShowBg").hide();        }).ajaxError(function(e,xhr,opt){            console.log(e,xhr,opt);            $("#ajaxShowBg").hide();        });    });</script>

更多的ajax方法可以参考:

http://api.jquery.com/jQuery.ajax/
http://www.w3school.com.cn/jquery/jquery_ref_ajax.asp

0 0
原创粉丝点击