A slightly different question that all the others out there... I am able to easily pass JSON from a PHP page to JavaScript using the jQuery.ajax()
method, but here is my situation:
I have a set of contact data in MySQL, each with firstname, lastname, lat, lng. I have created a page that on one half displays the contact data (firstname, lastname) in tabular format. On the other half, I have a Google Map that is populated with markers from the data set (lat, lng). Now, to allow the two halves to share the same dataset, there are two methods but I am happy with neither:
In the PHP file, pull the data from MySQL, use that data set for the table, then convert that data to JSON, write it out to a JavaScript variable and use that variable to populate the Google Map. Don't like doing this, as there are hundreds of data points, meaning the JSON string is very large and bloats the page, along with having all the data in human readable form in the source (I understand the data is there no matter what as in all cases it is on the client side, just more apparent here).
In the PHP file, pull the data from MySQL, use that data set for the table, then in my JavaScript, make an AJAX call via
jQuery.ajax()
to another PHP file that generates the JSON data. Hate this as it results in two calls to the same datasource.
I am sure I am missing something obvious here, any pointers/help?
EDIT: Per option #1 above, I am well aware of how to echo out JSON from PHP to JavaScript... just unhappy with both solutions (i.e. JSON is in source, or JSON is effectively a second call to the data source).