AJAX with care

:no:

AJAX/JSON is an extremely cool technology - using javascript to request content from servers for display. There is absolutely know doubt in my mind that it will be an important part of rich user experiences in the future of the web.

But - it shouldn’t be used everywhere. The complexity to really make it fly is expensive. If you have a simple page, or a low traffic page, or a basic application, attempting to add the layer of javascript necessary to manage the client-server communication is probably not worth it.

The Internet Explained

Tubes

Developing PHP5 code on a PHP4 server, that also has PHP5

.htaccess to run PHP5 on a server that defaults .php to PHP4, when your ultimate target is a PHP5 server.

.htaccess file


RewriteEngine   On
RewriteRule   ^index.php5$      - [L]
RewriteRule   ^exec.php$        - [L]
RewriteRule   ^(.*)\.php5?$     index.php5?page=$1
DirectoryIndex  index.php5

The advantage of this architecture is that since all the pages are delivered through index.php5, they are processed as PHP5, although they are named as .php.

Also - if you have a PHP5 application, you MAY be able to use the same approach, if you put PHP5 and PHP4 on the same server.

dojo validation

This is a dojo validation loop. Send it an array of input ids (with dojoTypes), and it will ensure they’re valid.


function checkValid(aValid)
{
        var i,e;
        for (i=0;i<aValid.length;i++)
        {
                e=dojo.byId(aValid[i]);
                if (!e.readOnly)
                {
                        e=dijit.byId(aValid[i]);
                        if (typeof e.isValid != 'undefined')
                                if (!e.isValid())
                                {
                                        alert(e.invalidMessage);
                                        e.focus();
                                        return false;
                                }
                }
        }
        return true;
}
</script>

PS - Visit http://dojotoolkit.org with FireFox, not IE

Ini processing into javascript


<html>
<body>
<?php
$ini_array=parse_ini_file('lxtest/ini/system.ini.php');
echo '<pre>';
var_dump($ini_array);
echo '</pre>';
echo '<hr />';
extract ($ini_array);
echo 'Database: '.$database.'<br />';
?>
<?=$database?>
</body>
<script>
alert("<?=$password?>");
</script>
</html>

This is the beginning of an adventure - to use PHP to inject strings into javascript for AJAX applications. Multi-lingual, fast and efficient. More posts later. Will probably require Apache adjustments to run .js files through PHP, but that’s okay!!!

:D