[英]simplify if statement in several AJAX
I need to use the same if..else
to deal with every AJAX data in my code. 我需要使用相同的
if..else
处理代码中的每个AJAX数据。
$.ajax({
url: "api/aall.json",
dataType:'json',
type: 'GET',
data: "data",
cache: false,
ifModified: true,
success: function getData(data){
console.log(data);
for(var i=0;i<7;i++){
// if...else
}
});
There are several AJAX get differnt: 有几种AJAX截然不同:
$.ajax({...});
$.ajax({...});
$.ajax({...});
$.ajax({...});
if...else code: 如果...其他代码:
if(MainClass_Code=="PD" || MainClass_Code=="CD"){
newsKindRepalce = "aipl";//news
}else if(MainClass_Code=="PF" || MainClass_Code=="JF"){
newsKindRepalce = "aopl";//international
}else if(MainClass_Code=="CU"){
newsKindRepalce = "acul";//culture
}else{
newsKindRepalce = "acn";//artist
}
It's would be very heavy when I use if...else
in my all AJAX to deal with data, how can I do to simplify this? 当我在所有AJAX中使用
if...else
来处理数据时,这将非常繁重,我该如何简化呢?
change your if else
to this: 将您的
if else
更改为此:
const code = { PD: "aipl", CD: "aipl", PF: "aopl", JF: "aopl", CU: "acul" };
newsKindRepalce = code.hasOwnProperty(MainClass_Code)
? code[MainClass_Code]
: "acn";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.