1 异步请求:
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 同步请求
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'
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 同步请求
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'
);
eg.
//判断权限
function judge_authority(val)
{
$.ajax({
type:'POST',
url:'data.php',
data: 'actionid='+ val,
async : false,
success:function(data){
if(data=='0'){
alert('没有权限进行此操作');
val=0;
}else{
val=1;
}
},
error : function(data) {
alert('执行出错');
}
});
//$.get("data.php?actionid"+val, function(data){ if(data==0){val=0;}else{val=1;}});
//$.post('data.php', { actionid: val }, function (data) { if(data==0){val=0;}else{val=1;} });
alert(val);
}