It seems to be a little loose sentence. Please dating please. Now···
For example, there is a TOP page on a shopping site or something, and there is a partial of New Items in it, and the frequency of adding products is high, and customers demand immediacy, but the TOP page includes New Items. Suppose that it was designed to be written out firmly on the server side with a single piece of HTML. If you do so, you will need to reload the entire TOP page to reload New Items, so you can either use JS to automatically reload the entire page, or no, that's not the case, so make it Ajax. It will be a partial reload.
There are usually two Ajax design methods considered here.
In other words, HTML is generated on the server side. Specifically, on the server side, it's like cutting out a partial template for New Items and adding new route and controller :: method ().
In other words, it generates HTML on the client side. Specifically, on the client side, it is a good idea to embed the template of the New Items part using jQuery-template or AngularJS, assign the JSON received by Ajax, and render it. Oh, you'll also add route and controller :: method ().
(The third hybrid method is to export the first JSON as part of text / html, though I've never done it).
Now, comparing the two, The former in terms of ** ease ** The latter in terms of ** API versatility **, Are likely to be superior to each other.
I recommend the latter. It's a beautiful design, and in some cases, it can be a stepping stone to propose open APIs (= create new jobs). Well, that's fine ...
By the way, if you choose the latter instead of the former, in addition to jQuery and AngularJS Gonyo Gonyo, there will be one more troublesome thing. The template engine bundled with the server-side application framework will usually have a filter function and some will use it, so you'll have to replace it with a JS implementation.
For example, in the controller $datetime = '2014-03-13T12:34:56.888Z'; In the template engine, the value assigned as
<?php echo date('Y year n month d day h:m', strtotime($datetime)); ?>
It's a little difficult if you write it out like that. You can calculate the date (...) part on the server side and pass it in JSON, but if you do so, the versatility of the API will drop sharply.
https://github.com/kvz/phpjs It's quick because you can use PHP's powerful functions in JS with the same interface. If you use this and rewrite it in JS, it will be easy. I'm happy.
By the way, there is something similar in Python Django. https://github.com/dryan/django-filters-js (Ruby was not found ...)
It's a devious approach, but it's a good option. I may be able to go home early tonight.
That's it!
It's a promotion, but this entry is also related,
http://j.inthemaking.net/ I tried to make it. You can see it on your PC, but it's for smartphones. If you don't mind, I'd be happy if you could use it to kill time.
Recommended Posts