简体   繁体   中英

Including dynamic content on a static HTML page

I've noticed on websites like IGN and Gamespot that their feature article and review pages are HTML (.html) with dynamic content like user comments included on the page.

How do they include this type of dynamic content in a static HTML page?

If I turn Javascript off and view one of their pages, they dynamic content disappears so I assume it's done with Javascript.

I'm interested in serving similar content and would like to do it via HTML instead of a dynamic PHP page with everything stored in a database (except for stuff like comments).

Hope that makes sense.

It's done with Javascript. The most common way to do this is to have Javascript on the page that accesses some sort of API that retrieves the appropriate comments (aka AJAX). You won't be able to access a database this way unless you expose that database using some kind of API (probably HTTP).

If you want something like this on your own site, look in to services like Disqus which store comments on their servers and retrieve them using Javascript.

One commonly used technique to achieve this is to use AJAX . Obviously the dynamic content must come from a dynamic server side script.

I don't know, but I'm guessing it's JavaScript ajax. There are a few solutions that could do this, but JavaScript is the best, check out MooTools (my personal favourite) and JQuery.

When you have the client-server relationship, there are often many things happening in the background.

For instance, Apache can be configured to parse any "file extension" with file ending .xxx as PHP. So, you can configure your Apache instance to parse PHP within .html files just as it would with .php files:

http://www.electrictoolbox.com/apache-parse-html-as-php/

And as well, you can serve different "content-types" to the browser, so that a PHP-parsed page can send, for instance, PDF content to the browser:

http://php.net/manual/en/function.header.php

Now, a possibly easier way is to use Apache's rewrite to take a URL request and rewrite it to a PHP page with the rest of the URL request being added as request attributes, such as in the Model-View-Controller pattern:

http://expressionengine.com/wiki/Remove_index.php_From_URLs/

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

So that a URL such as http://www.example.com/article/feature/my_story.html will actually be seen by the server's PHP parser as http://www.example.com/index.php?class=article&method=feature&id=my_story.html

And then you can use AJAX methods to specifically update a portion of a page, as has been mentioned in other answers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM