PHP to JSON on client side

DrooPy DoG

New Member
I'm using Rob Monies 'Jquery Week Calendar' to build a calendar application.I have a MSSQL DB a with table named 'dates' and the following fields:idstartendtitleI would like to query this DB in PHP and then pass the results to Javascript, Javascript will then render the events in the browser.The Javascript needs to receive the event details in JSON format as per the following example:\[code\]{"id":1,"start": 2010-10-09T13:00:00,"end":2010-10-09T14:00:00,"title":"Lunch with Mike"},{"id":2,"start": 2010-10-10T13:00:00,"end": 2010-10-10T14:00:00, "title":"Dev Meeting"}\[/code\]So far, to keep things simple I've just returned one row from the DB at a time, however - I will need the application to be able to render multiple events, as stored in the database.I've tried using \[code\]json_encode()\[/code\] to put the values into a var and pass them to a Javascript var called DB_events - if I return the DB_events in an alert box on the client side I see the following;\[code\]{"id":1, "start":2010-10-09T13:00:00, "end":2010-10-09T14:00:00,"title":"Lunch with Mike"}\[/code\]which looks ok, but when I do this in my code:\[code\]events : [DB_events]\[/code\]It doesn't work :(If I take PHP out of the equation, and just do the following on the client side:\[code\]var DB_events = {"id":1, "start":2010-10-09T13:00:00, "end":2010-10-09T14:00:00,"title":"Lunch with Mike"};\[/code\]and return DB_events in an alert box, I get:\[code\][object] [Object]\[/code\]But when I do this:\[code\]events : [DB_events]\[/code\]it works!Back to PHP
 
Back
Top