[hunchentoot-devel] ht-simple-ajax

Haris fbogdanovic at xnet.hr
Sun Apr 3 23:10:22 UTC 2011


> Use the parenscript function ps-inline instead of ps
> (:a :href (ps-inline (say-hi)) "Say Hi!")

I did that and now when I click Say hi link I just get Error on page on the 
bottom of the page, javascript error I guess.
Here is html generated from my code, maybe the error is more obvious this 
way

---------------------------------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns='http://www.w3.org/1999/xhtml'>
  <head>
    <title>
      ht-simple-ajax demo
    </title><script type='text/javascript'>
//<![CDATA[
function fetchURI(uri, callback) {
  var request;
  if (window.XMLHttpRequest) { request = new XMLHttpRequest(); }
  else {
    try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
      try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (ee) {
        request = null;
      }}}
  if (!request) alert("Browser couldn't make a request object.");

  request.open('GET', uri, true);
  request.onreadystatechange = function() {
    if (request.readyState != 4) return;
    if (((request.status>=200) && (request.status<300)) || (request.status 
== 304)) {
      var data = request.responseXML;
      if (callback!=null) { callback(data); }
    }
    else {
      alert('Error while fetching URI ' + uri);
    }
  }
  request.send(null);
  delete request;
}

function ajax_call(func, callback, args) {
  var uri = '/ajax/' + encodeURIComponent(func) + '/';
  var i;
  if (args.length > 0) {
    uri += '?'
    for (i = 0; i < args.length; ++i) {
      if (i > 0) { uri += '&' };
      uri += 'arg' + i + '=' + encodeURIComponent(args[i]);
    }
  }
  fetchURI(uri, callback);
}

function ajax_say_hi (name, callback) {
    ajax_call('SAY-HI', callback, [name]);
}
//]]>
</script>
    <script type='text/javascript'>function callback(response) {
    return alert(response.firstChild.firstChild.nodeValue);
};
function sayHi() {
    return ajax_say_hi(document.getElementById("name").value, callback);
};
    </script>
  </head>
  <body>
    <p>
      Please enter your name:
      <input id='name' type='text' />
    </p>
    <p>
      <a href='javascript:sayHi()'>
        Say Hi!
      </a>
    </p>
  </body>
</html>





More information about the Tbnl-devel mailing list