Which would be a better way to load data via ajax

Posted by Mike on Programmers See other posts from Programmers or by Mike
Published on 2012-06-12T19:56:18Z Indexed on 2012/06/12 22:47 UTC
Read the original article Hit count: 353

Filed under:
|
|
|

I am using google maps and returning html/lat/long from my MySQL database

Currently

  1. A user picks a business category e.g; "Video Production".
  2. an ajax call is sent to a CodeIgniter controller
  3. the Controller then queries the db, and returns the following data via JSON
    1. Lat/Long of the marker
    2. HTML for the popup window
    3. this is approximately 34 rows in the database across two tables per business
  4. the ajax call receives this data and then plots the marker along with the html onto the map

The data that is returned from the controller is one big json object... This is done for all businesses that exist in the Video Production category (currently approx 40 businesses). As you can see, pulling this data for multiple categories (100s of businesses) can get very very taxing on the server.

My question is

Would it be more beneficial to modify the process flow as such:

  1. a user picks a business category e.g; "Video Production".
  2. an ajax call is sent to a CodeIgniter controller
  3. the controller then queries the database for the location base information
    1. lat/long
    2. level (used to change marker icon color)
    3. This would be a single row per business with several columns
  4. the ajax call receives this data and then plots the marker on the map
  5. when the user clicks a marker an ajax call is sent to a CodeIgniter Controller
  6. the controller queries the database for the HTML and additional data based on business_id

and if not, what are some better suggestions to this problem?

In summary this means rather than including the HTML and additional data along for each business, only submitting minimal location information and then re-query for that information when each business marker is clicked.

Potential Downsides

  1. longer load times when a user clicks a marker icon
  2. more code??
  3. more queries to the database

© Programmers or respective owner

Related posts about php

Related posts about sql