0

I have many situations where I make AJAX call to server side to get some data. My question is:

Is it better to get the data back simply as JSON or XML, but then I need to use javascript to do all the input and it is impossible to use my server side variables of the user in this javascript (am I wrong here) or is it better to get back not only the database data but the whole HTML.

The first way would be to get back from AJAX call only the content of the table cells and do the whole table generating HTML in javascript. The second would be to call AJAX and get the whole HTML with the data in back from server side.

I am using the second approach now because it is easier for me to program in server side language, but I see two problems using this approach:

  1. Instead of getting only the data I get whole HTML back, which means for example that I am loading too much data every time instead of generating it on client.

  2. The data that I get back is only good for this particular "project", because it is already "formatted" with HTML code. If I would get the JSON raw data, I could reuse the serverside AJAX code to do something else with this data on some other page.

What is the best practice here?

4

1 回答 1

-1

不要尝试从服务器获取 HTML 或任何标记以显示在屏幕上。这是一个不好的做法。

另外,我更喜欢 JSON 而不是 XML。

编辑: http ://api.jquery.com/load/

于 2012-05-17T04:17:54.450 回答