views:

48

answers:

1

Hi

This is an ajax questions. I have a table this table shows users information at certain time depending on what settings the user sets.

Now in some cases a user will see the information right away and in some cases they won't it all depends on when they want to see the information.

Now what should I do?

Should I do? do a post and post their data and then do a ajax get after to get the table and render it?

*I probably could it all in the post but unless some huge performance gain is gained I rather not otherwise I have to do mix "success/fail" messages and the table to be rendered all in the same response.

So each one seems to have pluses and minuses.

Ajax way

  • don't have to worry about having a
    JavaScript solution that queries the database to figure out what their
    timezone is and then determine if the row should be added or not and any
    other headaches that comes with
    javascript dates.

  • Each row could potential have a
    different style to. This would
    mean I would have to possibly do a
    query to the database and figure it
    out or have hidden field in the page for easy access. With Ajax way I
    would not have to worry about it.

  • don't have to worry about making a
    manual row in javascript/jquery
    syntax what can be a pain to do if
    you have many columns.

Javascript way

  • Problem less of a performance hit since only have to potentially make one new or do nothing. Where otherwise I have to generate a new table regardless and if it has lots of rows in it that could be slow.
  • Have to rebind all jquery plugins that would be on the table. Or use jquery.live for everything else.

So I am not sure to me it seems like a hard choice.

+1  A: 

Unless I misunderstand what you want to do, why not do both in one solution?

Return a JSON response, so, when a user logs in, you post the information using an ajax call, and just return the data from the database. I tend to return either data or an error message, but you could have two objects in your json string, one for a possible error message and the other being the data that is being returned.

The javascript then can process the data as is needed.

So, you do both, it isn't an either/or decision.

James Black
hmm ya I know about Json response I use it for my error messages(since I could return multiple). I guess your saying do all the stuff on the serverside and return the result as a json?
chobo2
Yes, that would be the best approach, since it cuts down on server traffic, but allows the javascript to decide what to do with the information.
James Black