views:

67

answers:

2

I am searching for a Javascript Library Which has only AJAX no other feature. e.g. a Small Simple XMLHttp Wrapper.

A: 

Something like this, perhaps? (Original source)

(Why do you think you need a library for this? If it's that minimal, DIY!)

Matt Ball
A: 

Here' a small chunk of a JavaScript PHP wrapper I wrote a long time ago when I virtually knew nothing about JavaScript... it barely contains any AJAX methods, just wrapper functions that communicate with a PHP backend in order to allow PHP to do all the work...

In all honesty, to get what it seems you're looking for... just sit down and write yourself an AJAX library with all the common helper functions. It should take you a few hours at the most.

The Javascript:

(function() {

var
    PHPJS = window.PHPJS = window.$ = function() {
      return new PHPJS.Strings;
  };

PHPJS.Strings = PHPJS.prototype = {

    InitAJAX: function(Library, ServerString)
    {
        var ResultCache = document.body;
        var FunctionRequest;
        try {
            FunctionRequest = new XMLHttpRequest();
        } catch (e) {
            try {
                FunctionRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    FunctionRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                    throw new Error("The XMLHttpRequest() object is not supported by your browser.")
                    return false;
                }
            }
        }

        FunctionRequest.onreadystatechange = function() {
            if (FunctionRequest.readyState == 4 && FunctionRequest.status == 200) {
                ResultCache.innerHTML = FunctionRequest.responseText;
                return FunctionRequest.responseText;
            }
        } 

        switch (Library) {
            case 'Arrays' :
            FunctionRequest.open("GET", "functions/arrays-lib.php" + ServerString, true);
            break;
            case 'Math' :
            FunctionRequest.open("GET", "functions/math-lib.php" + ServerString, true);
            break;
            case 'Strings' :
            FunctionRequest.open("GET", "functions/strings-lib.php" + ServerString, true);
            break;
        }
        FunctionRequest.send(null);
    },

    /* String Functions */
    addcslashes: function(str, charlist)
    {
        return this.InitAJAX('Strings','?function=addcslashes&String='+str+'&Charlist='+charlist);
    },
    addslashes: function(str)
    {
        return this.InitAJAX('Strings','?function=addslashes&String='+str);
    },
    bin2hex: function(str)
    {
        return this.InitAJAX('Strings','?function=bin2hex&String='+str);
    },
    chop: function(str,charlist)
    {
        return this.InitAJAX('Strings','?function=chop&String='+str+'&Charlist='+charlist);
    },
    chr: function(int)
    {
        return this.InitAJAX('Strings','?function=chr&Int='+int);
    },
    chunk_split: function(str, chunklen, end)
    {
        return this.InitAJAX('Strings','?function=chunk_split&String='+str+'&Chunklen='+chunklen+'&End='+end);
    },
    convert_cyr_string: function(str)
    {
        return this.InitAJAX('Strings','?function=convert_cyr_string');
    },

    /* more functions... */
}

})();

//PHPJS.bin2hex('afsdfadsafdsafdasfsaf');   

The PHP:

<?php
switch($_GET['function']) {
    case 'addcslashes' :    
        $charlist = (@$_GET['Charlist']) ? ','.$_GET['Charlist'] : '';
        echo addcslashes($_GET['String'], $charlist);
    break;
    case 'addslashes' : 
        echo addslashes($_GET['String']);
    break;
    case 'bin2hex' :    
        echo bin2hex($_GET['String']);
    break;
    case 'chop' :   
        $charlist = (@$_GET['Charlist']) ? ','.$_GET['Charlist'] : '';
        echo rtrim($_GET['String'], $charlist);
    break;
    case 'chr' :
        echo chr($_GET['Int']);
    break;
    case 'chunk_split' :
        echo chunk_split($_GET['String'], @$_GET['Chunklen'], @$_GET['End']);
    break;
        /** ...etc, etc... **/
?>
Xaxis
This is not What I am looking for.