ajax数据中的jQuery条件语句 [英] jQuery Conditional statement inside ajax data
本文介绍了ajax数据中的jQuery条件语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以制作这样的东西吗?
Can I make something like this for example?
$.ajax({
url:'ajax.php',
type:'POST',
data: {
id: 3,
device: $("#ipole4").val(),
name: $("#ipole5").val(),
ip: $("#ipole6").val(),
method: $("#ipole7").val(),
if (2 == 2) {
'info':2
}
},
})
我只想在特殊情况下发送更多内容。
I just want to send something more in the special case.
推荐答案
您可以这样做,但不能使用您拥有的语法。您需要先创建对象,然后单独使用条件语句,如下所示:
You can do this, but not with the syntax you have. You need to create the object first, then use the condition statement separately, like this:
var data = {
'id': 3,
'device': $("#ipole4").val(),
'name': $("#ipole5").val(),
'ip': $("#ipole6").val(),
'method': $("#ipole7").val()
};
if (2 == 2)
data.info = 2;
$.ajax({
url:'ajax.php',
type:'POST',
data: data
}
这篇关于ajax数据中的jQuery条件语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文