Menu

Ajax

James Stortz

Fetching Content

asynchronous javascript and xml

Ajax

| OVERVIEW

Ajax content retrieval should be simple and universal, on.js makes everything possible in one easy step.

| KEYWORDS

  • this

| COMMANDS

  • 'GET'
  • 'POST'

GET

/**\    basic "GET"
\**/
/**\    fetch content
\**/

('GET')[on]("../ajax/get/url/")                     //the page to get
(   function()
    {
        console.log(this.responseText);             //the content fetched
    }
);


:::javascript

/**\    "GET" with variables        (first way)
\**/
/**\    fetch content
\**/

('GET')[on]("../ajax/get/url/?applesauce=true")     //the page to get
(   function()
    {
        console.log(this.responseText);             //the content fetched
    }
);


:::javascript

/**\    "GET" with variables        (second way)
\**/
/**\    fetch content
\**/

('GET applesauce=true')[on]("../ajax/get/url/")     //the page to get
(   function()
    {
        console.log(this.responseText);             //the content fetched
    }
);

POST

/**\    basic "POST"
\**/
/**\    fetch content
\**/

('POST')[on]("../ajax/post/url/")                   //the page to post to
(   function()
    {
        console.log(this.responseText);             //the content fetched
    }
);


:::javascript

/**\    "POST" with variables       (standard way)
\**/
/**\    fetch content
\**/

('POST applesauce=true')[on]("../ajax/post/url/")   //the page to post to
(   function()
    {
        console.log(this.responseText);             //the content fetched
    }
);


:::javascript

/**\    "POST" & "GET" with variables       (standard way)
\**/
/**\    fetch content
\**/

('POST applesauce=true')[on]("../ajax/post/url/?topic=food")    //the page to post/get
(   function()
    {
        console.log(this.responseText);                         //the content fetched
    }
);

on.js

return true;

A JavaScript Library


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.