Jump to content
Stef's Coding Community
Sign in to follow this  
dianikol85

Ajax response

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...