Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...