【发布时间】:2017-02-21 13:41:14
【问题描述】:
在控制器中我放置了 3 个用户:
@http.route('/test_json', type="json", auth="public")
def some_json(self):
return json.dumps({"id": 1,"name": "Leanne Graham"},{"id": 2,"name": "Leanne Graham 2"},{"id": 3,"name": "Leanne Graham 3"})
阿贾克斯
$.ajax({
type: "POST",
url: "/test_json",
async: false,
data: JSON.stringify({}),
contentType: "application/json",
complete: function (data) {
var mydata = JSON.stringify(data);
alert(mydata)
alert("How get only name in alert for user)
},
error: function () {
alert("Error")
}
});
在警报中获取
{"readyState":4,"responseText":"{\"jsonrpc\": \"2.0\", \"id\": null, \"result\": \"{\\\"id\\\": 1, \\\"name\\\": \\\"Leanne Graham\\\"}\"}","responseJSON":{"jsonrpc":"2.0","id":null,"result":"{\"id\": 1, \"name\": \"Leanne Graham\"}"},"status":200,"statusText":"OK"}
如何获取所有用户(3 个用户)和每个人的 ajax 警报显示名称?
【问题讨论】: