2

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

22
  • 8
    I highly recommend vapor.js Commented Oct 22, 2010 at 14:41
  • 2
    If something already exists. Why would I take the overhead of maintanance ? Commented Oct 22, 2010 at 14:46
  • 1
    Documentation is on GitHub: github.com/madrobby/vapor.js Commented Oct 22, 2010 at 14:53
  • 2
    LOL vapor.js is empty I can get vapor.packed.js But How can one understand from a compressed js. Commented Oct 22, 2010 at 15:11
  • 1
    I went to that link. the vapor.js file is 0KB. and there is nothing in it. The README just has a <script src='vapor.js'></script> But How to make an AJAX GET/POST request with it. or how to specify the callback is not written anywhere. Commented Oct 23, 2010 at 5:54

3 Answers 3

1

microajax is what I settled on.

Sign up to request clarification or add additional context in comments.

Comments

1

This is not a library but it is a "Small Simple XMLHttp Wrapper" I made:

//params format:"bob=hi&id=1295&lol=haha"
function ajax_post(post_url,params,success_callback,fail_callback,timeout)
{
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("POST",post_url, true);

    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    //xmlHttp.setRequestHeader("Connection", "close");

    xmlHttp.onreadystatechange=function()
    {
        if (xmlHttp.readyState == 4 ) 
        {
            clearTimeout(xmlHttpTimeout); 
            if(xmlHttp.status == 200)
            {
                success_callback();
            }
            else 
            {
                    fail_callback();
            }
        }
    }
    xmlHttp.send(params);

    var xmlHttpTimeout=setTimeout(ajaxTimeout,timeout);
    function ajaxTimeout()
    {
       xmlHttp.abort();
       fail_callback();
    }

}

function ajax_get(url,success_callback,fail_callback,timeout)
{
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("GET",url, true);

    xmlHttp.onreadystatechange=function()
    {
        if (xmlHttp.readyState == 4 ) 
        {
            clearTimeout(xmlHttpTimeout); 
            if(xmlHttp.status == 200)
            {
                success_callback(xmlHttp.responseText);
            }
            else 
            {
                    fail_callback();
            }
        }
    }
    xmlHttp.send();

    var xmlHttpTimeout=setTimeout(ajaxTimeout,timeout);
    function ajaxTimeout()
    {
       xmlHttp.abort();
       fail_callback();
    }

} 

1 Comment

Down-votes are acceptable, but please add a comment explaining your reasoning. Stack Exchange is a learning platform after all.
0

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... **/
?>

1 Comment

This is not What I am looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.