> > *views/default/index.html* > ... > <script> > $(function () { > $(document).ready(function () { > *// pie json url* > $.getJSON('127.0.0.1:8000/test/api/json_pie_test/1.json', > function(data) { > $('#pie_json').highcharts({ > ... > series: [{ > type: 'pie', > name: '{{=T('JSON') }} ', > data: data > }] > }); > }); >
The above JS code is making an Ajax call *after* the index page has loaded, so this chart cannot be drawn until after that Ajax call completes. > *// pie python for loop loaded faster, show pie chart first* > $('#pie_python').highcharts({ > ... > series: [{ > type: 'pie', > name: '{{=T('Python') }} ', > data: [ > {{for row in rows:}} > ['{{=T(row.product.name) }}', {{=row.price}} ], > {{pass}} > ] > }] > The above Python for loop runs on the server *before* the index page is sent to the browser. The data are therefore already available in the index page when it first loads, so the chart can be rendered immediately on page load without first having to make an Ajax call to get the data. So, this has nothing to do with a for loop vs. response.json -- it's just that in one case you have the data immediately available upon page load and in the other you have to first wait to get the data via an Ajax request. No matter how long the for loop takes, it always happens before the page is even sent to the browser, so it is not a relevant part of the comparison. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.