Json ma'lumotlarini tekshiruvchi odoo 9dan o'qing

Nazoratchiga 3 ta foydalanuvchi qo'ydim:

@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

$.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")
              }
         });

Ogohlantirish bo'lsin

{"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"}

Qanday qilib barcha foydalanuvchilar (3 foydalanuvchi) va ajax ogohlantirish belgisi har bir kishi uchun?

1

6 javoblar

@http.route('/test_json', type="json", auth="public")
def some_json(self):
    return json.dumps({"ids":[{"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 results = data[responseText"]["result"];
              var names = [];
              results.map(function(v){
                  names.push(v['name']);
              });
              alert(JSON.stringify(names));

        },
        error: function() {
              alert("Error")
              }
         });
0
qo'shib qo'ydi
Tnx yordam uchun, konsolda xato natijalari aniqlanmagan postimg.org/image/tpn0w37tx
qo'shib qo'ydi muallif Anastasia_, manba
@http.route('/test_json', type="json", auth="public")
def some_json(self):
    return json.dumps({"ids":[{"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 results = data[responseText"]["result"];
              var names = [];
              results.map(function(v){
                  names.push(v['name']);
              });
              alert(JSON.stringify(names));

        },
        error: function() {
              alert("Error")
              }
         });
0
qo'shib qo'ydi
Tnx yordam uchun, konsolda xato natijalari aniqlanmagan postimg.org/image/tpn0w37tx
qo'shib qo'ydi muallif Anastasia_, manba

json.dumps usulini o'qing Hujjatlar .

Methodning obj argumenti sifatida ishlatiladigan lug'at json ob'ektiga mos keladi va sizda faqat uchta "root" obyekti mavjud. Istagingizga erishish uchun barcha lug'atlaringizni boshqa lug'atga biriktirishni xohlaysiz:

@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"}})
0
qo'shib qo'ydi

json.dumps usulini o'qing Hujjatlar .

Methodning obj argumenti sifatida ishlatiladigan lug'at json ob'ektiga mos keladi va sizda faqat uchta "root" obyekti mavjud. Istagingizga erishish uchun barcha lug'atlaringizni boshqa lug'atga biriktirishni xohlaysiz:

@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"}})
0
qo'shib qo'ydi

nima uchun ogohlantirish, log va firebug foydalanish

misol

$ .ajax ({         turi: "Post",         url: "/ test_json",         async: noto'g'ri,         ma'lumotlar: JSON.stringify ({}),         contentType: "application/json",         tugallangan: funktsiya (ma'lumotlar) {

           },
    error: function() {
           console.log("error");
          }
     });
0
qo'shib qo'ydi

nima uchun ogohlantirish, log va firebug foydalanish

misol

$ .ajax ({         turi: "Post",         url: "/ test_json",         async: noto'g'ri,         ma'lumotlar: JSON.stringify ({}),         contentType: "application/json",         tugallangan: funktsiya (ma'lumotlar) {

           },
    error: function() {
           console.log("error");
          }
     });
0
qo'shib qo'ydi
Javascript UZB
Javascript UZB
99 ishtirokchilar

@js_uzb @vuejs_uz @react_uz @nodejs_uz @angular_uz @ngTashkent @yiiframework_uz @laravel_uz @linux_uzbek @python_uz @swift_uzb —————— @uzdevgroup @UzGeeksGroup ——— @UzDev_Jobs @jobs_uzb