AJaX for Weblogs

Source: Internet
Author: User
Tags expression php file return unique id expression engine
Ajax|web ext: Ajax for weblogs
The asynchronous JavaScript + XML (AJaX) solution is one this can bring happiness and bliss to Web designers and Web devel Opers alike. However, as with many Whiz-bang solutions caution is advised. Google uses it to great effect but personally I do they take it a bit too far. If a page change so much as it context changes then it have switched to a new URI. People often bookmark specific content that ' s within a specific context. As soon as this is no longer true it maybe a clue so you ' ve gone to far.

The "I thing I notice that the solutions are aimed at the heavier Web applications. Not surprising. Web applications suffer from constraints, Web clients impose on them. This solution gives them a way to check for dynamic content without reloading the current page.

So what does it does?

The IT ' s very simple. It uses Javascript to get data in a remote source and then loads that into a specified target. Whatever content you are like "to wherever" on the page. Jesse James Garrett of Adaptive Path has written a essay that covers the basics and provides more information on AJaX.

But lets get this sucker running, that ' s the fun bit. And it ' s pretty easy.

Step 1

Check If your Web client can actually handle the HTTP requests. We'll need to the use a javascipt to doing this.
var ajax=false;/* @cc_on @*//* @if (@_jscript_version >= 5) try {ajax = new ActiveXObject ("msxml2.xmlhttp"); catch (E) {try {ajax = new ActiveXObject ("Microsoft.XMLHTTP");} catch (E) {Ajax = false;}} @end @*/if (!ajax && typeof xmlhttprequest!= ' undefined ') {ajax = new XMLHttpRequest ();}
Step 2

Add the script that would pick up your data. In the I ' m not picking up XML data. But the weblog of your choice and in me case it's ExpressionEngine'll return the XHTML Which in turn would be inserted VI A The JavaScript InnerHTML Methode.
function getmyhtml (serverpage, ObjID) {if ((Serverpage.indexof ("http://www.yourdomain.com/")!=0)) return; var obj = document.getElementById (ObjID); Ajax.open ("Get", serverpage); Ajax.onreadystatechange = function () {if (ajax.readystate = 4 && ajax.status =) {obj.innerhtml = Ajax.resp Onsetext; } ajax.send (null);}
Step 3

The page that would display the dynamic content would need a placeholder element (tag) with a unique ID. The ID is used in the second script as a reference point to allow for insertion of the new dynamic content.
This URI in the "onload" is the one which would generate the content.

Step 4

The dynamic bit is parsed by the engine of your choice like; Moveable Type, Expression Engine, Word press etc. Of course can use any of the collecting content form a database.

In Expression Engine I ' m calling a template this collects the data for my calendar. The whole calendar is outputted as HTML and inserted via the script.

Lets say the URI is ' Http://www.yourdomain.com/tempate/pageid/', could in fact to be a PHP file or no other serverside s Cript solution. The page only needs to return HTML. This is a example in PHP.
<?php Echo ' <p>this is a php echo text</p> ';?>
And that ' s about it. It's all pretty old school but there you have it.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.