I am using .getJSON and returning a JSON object that I want to use an if statement to see what it is, and then do a specific function. Some examples of the JSON object getting passed in are:
{ "action" : [ { "seated" : "player6", "action" : "check", "bet": "" } ] }
{ {"turn" : [ { "card" : "30", } ] }
{ "action" : [ { "seated" : "player8", "action" : "raise", "bet": "18000" } ] }
{ {"flop" : [ { "card" : "33", "card" : "22", "card" : "40" } ] }
My getJson function is this:
$.getJSON('/gmae/action',
function(action) {
if (action.flop) {
setCard(0, action.flop[0].card);
setCard(1, action.flop[1].card);
setCard(2, action.flop[2].card);
alert("inflop")
}
if (action.action) {
setAction(action.action[0].seated, action.action[0].action, action.action[0].bet);
}
if (action.flop) {
setCard(0, action.flop[0].card);
setCard(1, action.flop[1].card);
setCard(2, action.flop[2].card);
alert("inflop")
}
else if (action.turn) {
setCard(3, action.turn[0].card);
}
else if (action.river) {
setCard(4, action.river[0].card);
}
开发者_如何学C else if (action.newhand) {
window.location.href=window.location.href;
}
}
If any of the "action"s are called it works fine and goes into the correct function. However if flop turn or river are the actions called from the JSON file then nothing happens. Does anyone have any idea why this is happening?
You have one extra {
in TURN and FLOP JSONs! Notice it? Here's how it should be:
{"turn" : [ { "card" : "30", } ] }
{"flop" : [ { "card" : "33", "card" : "22", "card" : "40" } ] }
精彩评论