Is it better to generate html for the ajax function in the JS handler or in the ajax PHP function?

I am developing some user interface for the product and we want to use jQuery and PHP. The content to create is a list of flags (10-100) that the user will change (deleting several at a time and changing entries). I thought I would try something new and ask StackOverflow (read: you), which is preferable: generate html in the php call and return or return the JSON data that jQuery can, and then run and create the html flags using.

I appreciate the feedback! My preferred method so far is to allow PHP to generate html because it knows more about the data during modification (it interacts with the database and can easily create html without having to pass identifiers, names, etc. to JSON )

Thank!

[Edit] Bandwidth is not a limitation. This is an internal intranet application. The information that should be printed for the user will not require modification of the dom after the fact (outside the flags, but built into the browser ...) some good comments were made on the amount of data that was returned:

gear back

Label

against. {"Label": "Unique_ID"}

obviously a lot of redundancy.

+3
3

/ . JSON , HTML , . HTML , ( , , , , ).

- HTML

HTML , -, , , HTML. JSON, script (, / ).

- JSON

, , JSON, . , = 2, "" "" . , script , ( ). , , .

- JSON

, , , . HTML- , - ( !) script, , ... JSON, script , .

+4

: . DOM , jQuery. , php blob.

, , , DOM , html blob php.

0

, .

HTML , , JavaScript. , , , , ( , ).

, HTML . , - , JSON - . , . , -, , , - .

JSON DOM- JavaScript.

Cheers,

0

Source: https://habr.com/ru/post/1769596/


All Articles