i have below code in ajax display data python stored in mongodb.
<script> function f(){ $(document).ready(function(){ $.get('ajax1', function(result){ $.each(result, function(index, element) { alert(json.stringify(element)); }); }); }); } </script> python call same:
@route('/ajax1') def func(): client = mongoclient() db = client.collection result = db.collection.find({},{'_id':0}).limit(2) arr = [] document in result: arr.append(doc) return (dict(items=arr)) i getting result below: [{"name":"abc","place":"someplace","designation":"des"}] [{"name":"nextname","place":"nextplace","designation":"nextdes"}]
i want print in format or in form of table:
abc someplace des nextname nextplace nextdes
can tell me how it? seems simple unaware of it. thanks!
to me make more sense use property names in javascript it's easier understand , more verbose.
<script> function f(){ $(document).ready(function(){ $.get('ajax1', function(result){ $.each(result, function(index, element) { var row = element.name + " " + element.place + " " + element.designation; console.log(row); }); }); }); } </script>
Comments
Post a Comment