Nano Ajax Library


Simply include the .js file in the web page:
<script src="nano.js"></script>


Shorthand for document.getElementById(id);
<div id="example1_container">click the button to change text</div>
<button onclick="gid('example1_container').innerHTML='Hello';">
  Change Text
click the button to change text
internally used to generate a timestamp (heartbeat) to prevent unwanted caching
ajxb(url, post_data)
Makes a synchronous (blocking) XMLHttpRequest (XHR) call and returns the server response

<div id="example2_container">click the button to change text</div>
<button onclick="alert(ajxb('docs/servertime.php?delay=5'));">
  Server Time
click the button to get server time
Note a delay is added to the server response to highlight the asynchronocy behavior.
ajxnb(xhr_object, url, callback_function, post_data)
Mostly used by ajxpgn to send and handle asynchronous XHR calls
<div id="example3_container">click the button to get server time</div>
<button onclick="example3_click();">Server Time</button>
function example3_click(){
var xhr_object=xmlHTTPRequestObject();

function example3_callback(xhr_object){return function(){
if (xhr_object.readyState==4)
click the button to get server time
ajxpgn(container_id, url, optional force_display, optional evaluate_scripts, post_data, callback_function)
One of the most used functions in nano.js
It loads the response of an XHR server response to a specified container
When force_display is set to true (false by default), even a hidden container becomes visible
Evaluate_scripts is set to false by default

ajxpgn displays the response to the most recent request (in-order delivery) by discarding in-flight XHR requests

<div id="example4_container">click the button to get server time</div>
 Server Time
click the button to get server time
Loads javascript functions on-demand

The following snippet will load a sayhi.js only once when clicking on the Load button.
Then you can type in javascript:sayhi();void(0); in the browser address to verify that it is dynamically loaded.
<button onclick="ajxjs(self.sayhi,'docs/sayhi.js')">Load</button>

Note the JavaScript function has to be functional variables:
sayhi=function(){...} //works
function sayhi(){...} //doesn't work
Dynamically loads and applies CSS file

Clicking on the Load button will change the look of all the buttons on this page:
<button onclick="ajxcss(self.cssloader,'docs/button.css')">Load</button>

Makes a cross-domain request without refreshing the current page

Note this experimental function does not XHR. It sends data to the server-side script using the url string, and executes the returned JavaScript code asynchronously.
Returns an XHR object. See ajxnb for sample use.

Windows 8 Metro App

Although the Windows 8 Metro App is a different run-time environment from a standard web browser, nano.js can still be used after the following patch:

Locate the following line in the ajxpgn function:
Then wrap around the code with the following lines:
MSApp.execUnsafeLocalFunction(function() {
If you manually alter the innerHTML content, for example when using ajxb, use the above treatment to allow script injection.

Our Services

Targeted Crawlers

Crawlers for content extraction, restoration and competitive intelligence gathering.

Learn More

Gyroscope™ ERP Solutions

Fully integrated enterprise solutions for rapid and steady growth.

Learn More


Self-updating websites with product catalog and payment processing.

Learn More

Featured Download

Nano AJAX Library v2.3

Tiny JavaScript library that brings you most of the AJAX functionality

Download    Documentation