jQuery Ajax - best method for data retrieval - JSON vs HTML data

Posted in CategoryGeneral Discussion
  • Terry Ogbemudia 4 months ago

    Returning formatted data will be a bad idea, just return JSON data and let the recieving side figure out how to use the data, this way more than one client can use the data in different ways

  • Hder 4 months ago

    Would like to get your opinion on best practices for data retrieval through jQuery/Ajax calls to a mySQL/PDO database.  Get HTML formatted data, or get JSON data and format in calling program?


    I can request data through AJAX, and have the PHP routine echo back a complete HTML formatted data set.  Then on the calling side, just append the data to the page as the HTML is already taken care of.  This method seems to work fine, is fast, and easy to code.

    Alternatively, I can have the PHP routine echo back the values in JSON format and have the calling routine place the data in HTML format for display.  Formatting would be more work, but doable nonetheless...

    Not sure which is best practice and why.  I'm thinking the JSON method is the better way?  Perhaps you can give some insight into this.  

    Thanks very much!


Please login or register to leave a response.