我控制器回報:閱讀JSON行
@http.route('/my_json', type="json", auth="public")
def some_json(self):
return json.dumps({"ids":[{"id": 1,"name": "Audi"},{"id": 2,"name": "BMW"},{"id": 3,"name": "OPEL"}]})
如何在DIV負載數據,例如新的HTML頁面。
1奧迪
2 BMW
3歐寶
功能callJson(){
$.ajax({
type: "POST",
url: "/test_json",
async: false,
data: JSON.stringify({}),
contentType: "application/json",
complete: function (data) {
alert(data["responseText"])
},
error: function() {
alert("Error")
}
});
警報返回:
{ 「jsonrpc」: 「2.0」, 「id」:null,「result」:「{\」ids \「:[{\」id \「:1,\」name \「:\」Audi \「},{\」id \ \「name \」:\「BMW \」},{\「 ID \ 「:3,\」 名稱\ 「:\」 歐寶\ 「}]}」