我目前以以下格式将JSON返回给ajax调用:
[
{“ username”:“ test3”,“ points”:62,“ sportName”:“篮球”},
{“ username”:“ test2”,“ points”:55,“ sportName”:“ Football” }
]
但是我想要这样:
{
“ data”:
[
{“ username”:“ test3”,“ points”:“ 62”,“ sportName”:“篮球”},
{“用户名”:“ test2”,“积分”:“ 55”,“ sportName”:“足球”}
]
}
返回它的函数(Laravel):
$scores=DB::select("SELECT user.username, points
FROM scores
JOIN users AS user ON user.id = scores.user_id
ORDER BY points DESC");
return json_encode($scores);
答案 0 :(得分:0)
您可以简单地做到这一点。
<button data-bgcolor="red">red</button>
<button data-bgcolor="#00f">blue</button>
<button data-bgcolor="white">white</button>