I am searching for a Javascript Library Which has only AJAX no other feature. e.g. a Small Simple XMLHttp Wrapper.
Asked
Active
Viewed 2,726 times
2
-
8I highly recommend [vapor.js](http://vaporjs.com/) – Nick Craver Oct 22 '10 at 14:41
-
You really just want an XML Http Wrapper? Why not write one yourself? That would probably be faster than searching and waiting for answers here... – Ivo Wetzel Oct 22 '10 at 14:44
-
@Matt, as long as you use the compressed version – Harmen Oct 22 '10 at 14:44
-
@Nick, I went to their github to check the source and it is empty 0 lines of code ?? Am I missing something?? – Teja Kantamneni Oct 22 '10 at 14:45
-
@Matt Especially `=>` :P – Ivo Wetzel Oct 22 '10 at 14:45
-
2If something already exists. Why would I take the overhead of maintanance ? – Neel Basu Oct 22 '10 at 14:46
-
I wonder if the vapor.js guys are looking for help, it seems like a great project. I bet I could double the size, functionality, and speed of their code base with very little effort – Matt Ball Oct 22 '10 at 14:48
-
@user: "maintenance?" Really? The only browser you have to adjust for is `!@#$%^&*ing IE`, and their release cycles aren't exactly _"speedy"_ – Matt Ball Oct 22 '10 at 14:50
-
@Nick I am wondering why no documentation besides small Getting Started is included. – Eugene Mayevski 'Callback Oct 22 '10 at 14:50
-
Where is the documentations for vapor.js – Neel Basu Oct 22 '10 at 14:52
-
1Documentation is on GitHub: http://github.com/madrobby/vapor.js – Donut Oct 22 '10 at 14:53
-
@matt Support vapor.js on MSO! http://meta.stackexchange.com/questions/53346/open-source-advertising-sidebar-2h-2010/67974#67974 – Yi Jiang Oct 22 '10 at 14:56
-
2LOL vapor.js is empty I can get vapor.packed.js But How can one understand from a compressed js. – Neel Basu Oct 22 '10 at 15:11
-
@user: `vapor.packed.js` will actually yield worse performance (in most cases) than the regular `vapor.js`. However I can recommend two alternatives (1) check out [vapor.min.js](http://github.com/madrobby/vapor.js/blob/master/vapor.min.js) or (2) just include the following HTML snippet in your page: – Matt Ball Oct 22 '10 at 15:37
-
@Matt Ball vapor.min.js is empty on your link. – Neel Basu Oct 22 '10 at 15:57
-
@user you should really check out the [vapor.js performance graph](http://vaporjs.com/#graph), that might help clear things up – Matt Ball Oct 22 '10 at 16:09
-
I've already seen the Graph. But where is the docs ? – Neel Basu Oct 22 '10 at 16:47
-
@user: [Donut](http://stackoverflow.com/users/121493/) already posted a link to the docs. Here it is again: http://github.com/madrobby/vapor.js – Matt Ball Oct 22 '10 at 23:23
-
1I went to that link. the vapor.js file is 0KB. and there is nothing in it. The README just has a `` But How to make an AJAX GET/POST request with it. or how to specify the callback is not written anywhere. – Neel Basu Oct 23 '10 at 05:54
-
1Sadly, the answers to this question are completely useless. – Andres Riofrio Jul 25 '12 at 06:07
-
@NeelBasu: vapor.js was a joke project to encourage people to learn javascript instead of depending on libraries like jQuery. So to make ajax request with vapor.js you'd use xmlHTTPrequest. – slebetman Oct 24 '13 at 02:35
-
FWIW, for my own personal code where I prefer minimal use of libraries (meaning, none at all) I use the xmlHTTPrequest shim found on the wikipedia article for xmlHTTPrequest to make it cross-browser: http://en.wikipedia.org/wiki/XMLHttpRequest – slebetman Oct 24 '13 at 02:38
3 Answers
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();
}
}

Hello World
- 925
- 7
- 18
-
3Down-votes are acceptable, but please add a comment explaining your reasoning. Stack Exchange is a learning platform after all. – Hello World Jul 26 '14 at 15:02
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... **/
?>

Xaxis
- 1,935
- 15
- 17