我试图在特定条件下进入ajax成功回调。我正在向ajax函数传递一个参数,并且基于参数匹配我正在尝试执行该函数。
我有一个if条件,如果参数是abc
然后url将是一些东西,如果参数是xyz
然后我试图跳转到成功函数。但是我无法做到。我怎么能这样做,这就是我试图做的事情。
function Call(type){
$.ajax({
if(type != 'xyz'){
var url = "/param1/api/me?id="+kId+"&clickType="+type;
}else{
//jump to success callback
}
success = function(data){
if(type == "abc"){
console.log('abc');
} else if(type == "asd"){
console.log('asd');
} else if(type == "gst"){
console.log('gst');
} else if(type == "xyz"){
console.log('xyz');
};
});
});
}
哦。你的意思是这样的?
function Call(type){
if(type != 'xyz'){
$.ajax({
url: "/param1/api/me?id="+kId+"&clickType="+type,
success: function (res) {
console.log(res);
}
});
}elseif(type == "abc"){
console.log('abc');
} else if(type == "asd"){
console.log('asd');
} else if(type == "gst"){
console.log('gst');
} else if(type == "xyz"){
console.log('xyz');
}
}
试试这段代码。
$.ajax({
type: "POST",
url: ajaxurl,
data: {},
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.d == "-505") {
// Error page
}
else if (data.d == "-501") {
// other page
}
successfunction(data);
},
error: function (data) {
//$.messager.alert('Warning', errormessage);
}
});