例如,我有这个 ajax 函数,但我只能在这里调用一个 json,添加什么代码才能获得超过 1 个 json:
var blue_name = $("#blue_team #blue_name").val().trim();
var blue_type = $("#blue_team #blue_type").val().trim();
var red_name = $("#red_team #red_name").val().trim();
var red_type = $("#red_team #red_type").val().trim();
$.ajax({
url: "battle_review.php",
type: "post",
datatype: "json",
data: { bname: blue_name
btype: blue_type
rname: red_name
rtype: red_type},
success:function(data){
var toAppend = '';
if(typeof data === "object"){
for(var i=0;i<data.length;i++){
//append data here
}
$("#table1").append(toAppend);// first json
}
}
});
这是我的 php 代码,我如何将数据放在我想要的 json 上是我可以获得两个 json 的 $blue 和 $red 怎么做?:
//get blue_team attributes
$blue = array();
$blue_result = $db->dataWarrior($battle,$name);
foreach($blue_result as $warrior){
$blue[] = $names;
}
//get red_team attributes
$red = array();
$red_result = $db->dataWarrior($battle,$name);
foreach($red_result as $warrior){
$red[] = $names;
}
echo json_encode(array('red'=>$red,'blue'=>$blue));