CakePHP: JSON vs. AJAX

I know that the title of this question can be a little misleading; I understand that JSON is a way to format data, and AJAX is a way to pull / remove updates from / to the server without updating. I ask because I legally do not have much experience in this area.

Given that I have CakePHP web application: This is just a matter of preference if I choose

  • To use JSON to pull / pop data, and then use a client-side script to refresh the page?
  • To use AJAX to get the full HTML snippet from the server and just paste it into the page?

The only differences that I see between the two are that JSON will mean less server load and bandwidth usage, and perhaps in what language is the developer more convenient to use (can JSON mean more client scripts?).

Can someone shed some light on this question for me?

+5
source share
1 answer
Good question. Especially in those days when things like Backbone.js became more popular.

Let’s look at it step by step.

-, JSON, HTML, , . HTML JSON, , , CakePHP , , , , , , /, (JSON HTML). , , PHP, , , .

, JSON. , .

JSON, . , - tweetdeck feeds, , ; , , .. , HTML . JSON , , .

"" , , - , .., . AJAX ( ).

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

, HTML , AJAX, . , AJAX , AJAX, "" HTML-, AJAX , . , javascript, javascript. , - Mustache.

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

:

html . JSON, . - AJAX, JSON. , if data.status == 'awesome' .. AJAX -, - pjax () HTML . javascript - HTML . , , , , .

pjax, javascript- html . http://pjax.heroku.com/

DHH Hacker , Basecamp; , MVC.

https://news.ycombinator.com/item?id=3603898

. LinkedIn , . http://engineering.linkedin.com/frontend/leaving-jsps-dust-moving-linkedin-dustjs-client-side-templates

+3

All Articles