dianikol85 Posted June 20, 2011 Report Share Posted June 20, 2011 Hello to all! Just a quick question. Let's say i make an ajax request and it returns a table with some data from a database. My questions is which format is better practice to return this table back? As a json or html? For example take the KS forum. In Recent Topics block after the title of the post you can view with a pop up a preview of the post using ajax. If you open the firebug and view the ajax call it returns the html with tha data. Also the forum every 3-4 minutes also make a ajax call to load new posts Recent Topics block. Again open firebug and see what it returns. This call returns a json object that contains the html. What is the difference between these two ajax responses? Thanks Quote Link to comment Share on other sites More sharing options...
BeeDev Posted June 20, 2011 Report Share Posted June 20, 2011 json is easier to manipulate with javascript than pure HTML. However if you don't need to manipulate the returned data, then HTML is much easier. I think that's the main reason why some are HTML and some are JSon. It depends on what you need to do with the data. If you're just going to slap the returned table into an html element, then returning the data as HTML makes sense. Quote Link to comment Share on other sites More sharing options...
dianikol85 Posted June 20, 2011 Author Report Share Posted June 20, 2011 That's what i thought. JSON is to manipulate the returning data. I guess that's its use. It isn't for faster response or something. For example if you return different types of data in a call then use json to manipulate what are you going to do with each type. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.