Jquery中Ajax/Post同步和异步请求


011 异步请求:
02   1.1 $.ajax
03      $.ajax({
04               url : 'your url',
05               data:{name:value},
06               cache : false,
07               async : true,
08               type : "POST",
09               dataType : 'json/xml/html',
10               success : function (result){
11                   do something....
12               }
13           });
14   2 同步请求
15   2.1 $.ajax
16      $.ajax({
17               url : 'your url',
18               data:{name:value},
19               cache : false,
20               async : false,
21               type : "POST",
22               dataType : 'json/xml/html',
23               success : function (result){
24                   do something....
25               }
26           });
27   2.2 $.post
28     $.post(
29               'your url',
30               {name:value},
31               function(data) {
32                   do something...
33               },
34           'json/xml/html'
35           );
或者采用以下方法

在全局设置:

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


1$.get("register/RegisterState", {test : 12}, function(data, status) { 
2    if (status == "success") { 
3            data = eval("(" + data + ")"); 
4        aDataSet = data; 
5        alert("data is " + aDataSet); 
6    else 
7            alert("wrong"); 
8         
9});