Jquery中Ajax/Post同步和異步請(qǐng)求



 1 異步請(qǐng)求:
    1.1 $.ajax
       $.ajax({
                url : 'your url',
                data:{name:value},
                cache : false, 
                async : true,
                type : "POST",
                dataType : 'json/xml/html',
                success : function (result){
                    do something....
                }
            });
    2 同步請(qǐng)求
    2.1 $.ajax
       $.ajax({
                url : 'your url',
                data:{name:value},
                cache : false, 
                async : false,
                type : "POST",
                dataType : 'json/xml/html',
                success : function (result){
                    do something....
                }
            });
    2.2 $.post
      $.post(
                'your url',
                {name:value},
                function(data) {
                    do something...
                },
            'json/xml/html'
            );
或者采用以下方法


在全局設(shè)置:


 $.ajaxSetup({  
    async : false  
});   
然后再使用post或get方法




$.get("register/RegisterState", {test : 12}, function(data, status) {  
    if (status == "success") {  
            data = eval("("   data   ")");  
        aDataSet = data;  
        alert("data is "   aDataSet);  
    } else {  
            alert("wrong");  
         }  
});  


原文鏈接:Jquery中Ajax/Post同步和異步請(qǐng)求