我对ajax调用和jquery很新,所以我知道这是可怕的错误,但我有三个div,我有多个json文件,每个文件都有三个对象。这些对象被称为ying,neutral或者yang,并且我试图将ying中性和阳性对象放置在它们相应的ying中性和阳性div中。请告诉我如何重写我的脚本来做我想做的事情。 我已经在互联网上搜索了一个具体的例子,把一个json文件分解成多个div,但找不到任何东西。如何在单独的ajax调用中将单独的json对象从单独的div中放入同一个文件中?
谢谢您的阅读和任何建议,你可能有。
这里是HTML和CSS
#categoryContainer{
text-align:center;
border: solid black 1px;
margin-bottom: 20px;
border-radius: 5px;
padding-bottom:20px;
}
.category{
display: inline-block;
width:33%;
box-sizing: border-box;
border: solid black 1px;
border-radius: 5px;
}
.foodBtnContainer{
text-align:center;
}
.foodBtn{
box-sizing: border-box;
width: 24%;
height: 56px;
border-radius: 20px;
box-shadow: none;
}
li{
list-style: none;
}
Categories
Ying
Neutral
Yang
VEGETABLES
FRUIT
GRAINS
BEANS
NUTS
OILS
SPREADS
SWEETENERS
SEASONINGS
SEAWEED
ANIMAL
SEAFOOD/SHELLFISH
SUPPLEMENTS/HERBS
TEA/BEVERAGES
ALCOHOL
,这里是什么,我想用我的脚本
$(document).ready(function(){
$("#vegetables").click(function(){
$.ajax({
dataType: "json",
url: "veggies.json",
data: 'json',
success: function{
if(object=="yang"){
.appendTo("#yang");
}
else if(object=="neutral"){
.appendTo("#neutral");
}
else if(object=="ying"){
.appendTo("#ying");
}
}
});
$("#vegetables").unbind('click');
});
});
完成一个非常粗糙的伪代码和这里是JSON
ying{
"one": "cranberries",
"two": "cucumbers",
"three": "dandelion greens"
}
neutral{
"one": "alfalfa sprouts",
"two": "arrow root",
"three": "artichoke"
}
yang{
"one": "plantains",
"two": "plums",
"three": "pomegranates"
}
+0
您的JSON似乎无效格式。 –
2015-01-21 07:17:24