HTML_AJAX
[ AdvancedSearch | AreaMap ]
|
|
|
HTML_AJAX Manual
What is AJAXAt its core AJAX is a simple technique combining a number of techniques that have been around in web development for years. You take JavaScript and use it to manipulate the DOM of the Browsers. To that you add a web server running a server side language like PHP. Then you combine the two parts using a communication layer that is hidden from the person sitting at their browser. This hidden communication usually takes place using a built in JavaScript object called XMLHttpRequest, but it can also take place with IFrames, dynamic Script tags and lots of other ways. XMLHttpRequest has the largest feature set and most complete API so it's the best option for the communications channel and it's what HTML_AJAX uses where possible, falling back to using hidden IFrames if support for XMLHttpRequest doesn't exist. You might have thought that AJAX was just flashy JavaScript, the animations and effects of "Web 2.0". It's not. Don't worry, though, JavaScript is part of AJAX. In order to complete the usability puzzle, you may want to use some of its effects. As for "Web 2.0" there isn't any official definition, so as long as you make a good looking site, call it "Web 2.0" and move on. If you're interested in learning more about AJAX you might want to check out Joshua Eichorn?'s AJAX book. It covers a lot of ground from different data encodings like XML or JSON to usability. It also includes a large number of examples that will help you see how the whole picture fits together. If you're scared of JavaScript (the J in AJAX) you might want to brush up on it. The Learning Resources Page contains some books and websites you might find useful. Why AJAXSo why should you use AJAX? This is both simple and complex. You should use AJAX because it allows you to introduce new content into web pages without reloading the entire page. This ability allows you to access large datasets in a fast transparent manner, giving you all the power of a thick client server application development environment, without all the deployment hassles. More Here What is HTML_AJAXHTML_AJAX is a PHP and JavaScript library released through the [PEAR that gives you an extremely featureful communication layer plus a lot of useful related tools. It doesn't include effects or animations or drag n drop. If you're looking for those I recommend using jQuery or mootools. HTML_AJAX allows for (at least aims for) the following AJAX programming styles
HTML_AJAX has a bunch of other features these are covered in later parts of this manual Why HTML_AJAXSo why should you use HTML_AJAX instead of some other AJAX library. HTML_AJAX provides advanced communications features (queues, pluggable serialization/data encoding, error handling), great PHP integration (proxied classes, helpers, action based development), and an easy to use API. It is designed by PHP developers for PHP developers and works hard to present AJAX in a way that is accessible and easy to use. But in the end what library you use is just a personal preference. Some other library might fit you (or your project) better, there is no best approach just lots of options (some good and some bad). Remember HTML_AJAX is well prefixed and doesn't mess with core JavaScript prototypes so its easy to mix with other libraries. Getting startedHTML_AJAX allows for a lot of different coding styles, which is one of its problems. You just got started and now you need to make decisions. But since I'm the author I'll help you out getting started by using the JavaScript API. Installing HTML_AJAXBut before we can do that lets take a step back and get things installed. If you don't have PEAR you have a couple options, you can [install PEAR] (yes even on shared hosts with only ftp access) or you can download HTML_AJAX and install it by hand. You can grab the package from: http://pear.php.net/package/HTML_AJAX/download
AJAX.php and AJAX expect to be placed in a directory named HTML that sits somewhere in your include_path. js contains all the JavaScript files that are used by HTML_AJAX. You have 2 options for these, you can copy them into your webroot and handle the JavaScript includes by yourself (a concatenated file HTML_AJAX.js is included for this purpose) or you can use the HTML_AJAX_Server class (don't worry we're covering it next) in which case put the js files where ever you want, just make sure your web server can access them and you remember where you put them. HTML_AJAX_ServerOk so now you have the install done you'll want to take a look at HTML_AJAX_Server (And for you framework developers out there, no you don't have to use it, but remember I'm making choices in this manual so we're going to.). In its most basic usage you make a new PHP script, lets call it ajax.php, in you put:
Pretty simple right, now for those of you who didn't use the PEAR installer and you still want to use HTML_AJAX_Server to serve up the JavaScript library code then you'll need to add 1 line.
But if you used PEAR just ignore that line, the installer did some magic on install time and prefilled that value for you. Making an AJAX request HTML_AJAX.grabSo now all the setup is done and we can make an AJAX request.
[Run IT] As you can see grab is simple. The first parameter examplefile.html is the the url to load, and the second is an anonymous JavaScript function to call when the request is complete. There are a couple of items to note:
HTML_AJAX.postNow if you wanted to make a POST request instead of a the GET request that grab did just use HTML_AJAX.post. Post is setup so it will look to PHP like a form was submitted so $_POST will be automatically be populated. Its basic usage looks like: HTML_AJAX.replaceHTML_AJAX.formSubmitExporting PHP ClassesRegistering Classes in ajax.phpOptions for lots of ClassesSetup MethodsSetup ObjectsHTML_AJAX.callJavaScript proxies of PHP ClassesChanging the formating/disabling the default Loading indicatorThere are a couple different options You can override the loading js functions (HTML_AJAX.Open, HTML_AJAX.Load) http://svn.bluga.net/HTML_AJAX/trunk/js/Loading.js or you can create a new div with an id of HTML_AJAX_LOADING this will be shown instead of the default one. Manual Author(s)This manual was written by Joshua Eichorn?, the original author of HTML_AJAX and author of [Understanding AJAX], an [AJAX Book] which covers the topic of AJAX a lot more then this manual. It doesn't have the same level of detail on HTML_AJAX though it does use it, and Scriptaculous and Sarissa in examples. Others have helped with this manual they include:
This site powered by YaWiki 0.22 beta. |