Jquery中Ajax的几种用法

$.ajax()

$.ajax({
        type:'GET',                // 请求方法: GET/POST, 默认:GET
        url:'ajax/ajax_checkAccountUserName', // 请求的地址
        data:{param:'request'}, // 请求参数
        dataType:'json',        // 数据格式, json/xml/...
        timeout:3000,           // 请求的超时时间(单位:毫秒)。
        cache:false,            // 是否缓存上一次的数据,默认:true
        async:true,             // 同步/异步请求
        beforeSend:function(){  // 发送请求前调用(一般不需要此函数)
            alert('before send');
        },
        success:function(data){ // 请求成功后的回调函数
            alert("$.ajax->" + data.account);
        },
        error: function(XMLHttpRequest, errMsg, errThrown) { //请求失败调用
            alert(XMLHttpRequest.status);
            alert(XMLHttpRequest.readyState);
            alert(errMsg);
        }
    });

$.get()

$.get(
        'ajax/ajax_checkAccountUserName',
        {param:'admin'}, // 请求参数(可以省略)
        function(data) { // 请求成功后的回调函数(可以省略)
            alert("$.get->" + data.account);
        },
        'json'
    );

$.post()

$.post(
        'ajax/ajax_checkAccountUserName',
        {param:'admin2'}, // 请求参数(可以省略)
        function(data) { // 请求成功后的回调函数(可以省略)
            alert("$.post->" + data.account);
        },
        'json'
    );

$.getJSON()

$.getJSON(
        'ajax/ajax_checkAccountUserName',
        {param:'admin'},
        function(data) {
            alert("$.getJSON->" + data.account);
        }
    );

 补充:$.get()  $.post()  $.getJSON() 的同步/异步请求方法

$.ajaxSettings.async = false;
作者:踮起脚尖眺望
出处:http://www.cnblogs.com/wangj1130
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/wangj1130/p/4852271.html