Search results for 'AJAX'. 3 post(s) found.

  1. 2009/08/28 Javascript based query parser for AJAX application
  2. 2009/08/22 Javascript Confirmation
  3. 2009/07/01 Simple RSS Reader based on javascript
2009/08/28 08:32

Javascript based query parser for AJAX application


When you want to pass data from one web page to another when server-side scripting is not available, and without setting a cookie? Here's the really good javascript you can use.

<script>
function QueryParser(str)
{
  if (str)
  {
    str = unescape(str);
    if (str.indexOf("?") === 0)
    {
      str = str.substring(1);
    }
    var args = str.split("&");
    for (var i = 0; i < args.length; i++)
    {
      var pair = args[i].split("=");
      if (pair.length >= 1)
      {
        var prop = pair.shift();
        this[prop] = (pair.length == 1) ? pair[0] : (pair.length > 1) ? pair.join('=') : '';
      }
    }
  }
  this.set = function (prop, value) { return this[prop] = value; };
  this.clear = function (prop)
  {
    if(typeof this[prop] !== 'undefined')
    {
      this.set(prop, null);
      return true;
    }
    else { return false; }
  };
  this.build = function (baseURL, hashName)
  {
    baseURL = (!baseURL || typeof baseURL !== 'string') ? '?' : (baseURL.indexOf("?") === -1) ? (baseURL + '?') : baseURL;
    hashName = (!hashName || typeof hashName !== 'string') ? '' : (hashName.indexOf("#") === -1) ? ('#' + hashName) :

hashName;
    var strArray = [];
    for (var prop in this)
    {
      if (typeof this[prop] !== 'undefined' && typeof this[prop] !== 'function' && this[prop] !== null)
      {
        strArray.push([prop, '=', this[prop]].join(''));
      }
    }
    return baseURL + strArray.join('&') + hashName;
  };
  this.buildLink = function (baseURL, linkTxt)
  {
    var url = this.build(baseURL);
    return [ '<a href="', url, '">', ((!linkTxt) ? url : linkTxt), '</a>' ].join('');
  };
}
var $q = new QueryParser(location.search);
</script>


Following is the simple example for above javascript.

EXAMPLE
URL: http://www.mydomain.com/mydir/page.h...&potential=110
$q.name will hold the value 'Super Coder'
$q.rank will hold the value '9999999999'
$q.potential will hold the value '110'
Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.

2009/08/22 22:32

Javascript Confirmation


A javascript confirmation box can be a handy way to give your visitors a choice of whether or not an action is performed. A confirmation box will pop up much like an alert box, but will allow the viewer to press an "OK" or "Cancel" button. Here is the basic command for creating a confirmation box:

var where_to= confirm("Do you really want to go to this page??");

if (where_to== true)
 {
   window.location="http://yourplace.com/yourpage.htm";
 }
else
 {
  window.location="http://www.strcpy.com";
  }

This is also very useful function if you are planning to develop AJAX applications.
Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.

2009/07/01 14:21

Simple RSS Reader based on javascript


Here's the simple AJAX application getting RSS data that does not use any kind of server resource except java script file itself.

I order to make script simply I designed simple javascript class at http://kurapa.com/js/xml.js.

<html>

<script type='text/javascript' src='http://kurapa.com/js/xml.js'></script>

<script language=javascript>
  function xml_call_back_sample( content)
  {
    RSS = new kRSS(content);

    // put HTML into content
    document.getElementById("content").innerHTML = "<font color=green><strong>" + RSS.get(0, "title") + "</strong></font><br>" + RSS.get(0, "description") + "<br><br>";;
    for( i=1; i<RSS.count(); i++)
      document.getElementById("content").innerHTML += "<font color=green><strong>" + RSS.get(i, "title") + "</strong></font><br>" + RSS.get(i, "description") + "<br><br>";
  }
 
  function getitnow()
  {
    // get RSS and define call back function which will be called when the RSS data is read completely
    kAJAX_run( 'http://RSS.cnn.com/RSS/edition.RSS', xml_call_back_sample);
  }
</script>

<input type=button value='--- get 1 ---' onclick='javascript:getitnow()'>
<div id="content">
click above button to get RSS data from CNN
</div>

</html>



 

Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.