[hunchentoot-devel] ht-simple-ajax
Andy Peterson
andy.arvid at gmail.com
Mon Apr 4 01:21:01 UTC 2011
Your html is correct and works. I used hunchentoot to dispatch it as a
static html file and it communicates with the ajax-processor I created
from your previous code.
The problem is probably with your ajax response.
If using chrome, developer tools will show the ajax request/response.
If using Firefox, use firebug.
andy
On Sun, Apr 3, 2011 at 7:10 PM, Haris <fbogdanovic at xnet.hr> wrote:
>> 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>
>
>
> _______________________________________________
> tbnl-devel site list
> tbnl-devel at common-lisp.net
> http://common-lisp.net/mailman/listinfo/tbnl-devel
>
More information about the Tbnl-devel
mailing list