Forum Moderators: open

Message Too Old, No Replies

Best way to use AJAX and handle responses?

Curious to hear opinions on best way to use AJAX and JSON

         

Parlays

7:57 pm on Apr 8, 2009 (gmt 0)

10+ Year Member



Hello everybody,

I currently like to use AJAX with JSON. I send variables to my PHP code, and have it send back data in a JSON response. I then parse that JSON data and insert it into my HTML to create new table rows and links (for example). If I need to create new event handlers, it is all ready on the client side to create those once the data arrives?

What methods do you recommend for inserting new HTML data and registering new javascript like event handlers?

Gibble

8:27 pm on Apr 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use a combination of JSON and XML depending on the situation.

Typically JSON, but in the event that I return a large result set that needs to be transformed into an html table, it's generally faster to use XSL on the client (or on the server and return the HTML).

It varies given the circumstance.

Parlays

10:31 pm on Apr 8, 2009 (gmt 0)

10+ Year Member



Cool, but what about when you want to attach new click event handlers to the content or just run some new javascript. Do you include that javascript in the reponse or do you have it ready in the response function?

Gibble

1:55 pm on Apr 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use jQuery selectors after the html is in the dom to find and attach events to the elements