callback on an anchor tag

960 views
Skip to first unread message

Toby Shepard

unread,
Jul 24, 2012, 5:21:59 PM7/24/12
to web...@googlegroups.com
Working through the html helper docs,
I decided to try the callback parameter
to the anchor tag:


{{=A("CLICK ME!!", callback=URL('http://mysite.com/foo.html'),
target='hater')}}
{{=DIV(_id = 'hater')}}

foo.html delivers a bit of content. This did not work.
Viewing the source, I see that the tag was rendered like this:

<a href="#null"
onclick="ajax(&#x27;/css/edit/http://register.rcsreg.com/foo.html&#x27;,[],&#x27;hater&#x27;);return
false;">CLICK ME!!</a>

That doesn't so good. Am I doing something wrong?

Thanks,

Tobiah

Massimo Di Pierro

unread,
Jul 24, 2012, 9:48:03 PM7/24/12
to web...@googlegroups.com
{{=A("CLICK ME!!", callback=URL('http://mysite.com/foo.html'), 
target='hater')}} 

should be

{{=A("CLICK ME!!", callback='http://mysite.com/foo.html',target='hater')}} 

which would produce:

<a href="#null" onclick="ajax(&#x27;http://mysite.com/foo.html&#x27;,[],&#x27;hater&#x27;);return false">CLICK ME!!</a>

and that is what is expected. Perhaps I misunderstand the question.

Anthony

unread,
Jul 24, 2012, 9:53:34 PM7/24/12
to web...@googlegroups.com
{{=A("CLICK ME!!", callback=URL('http://mysite.com/foo.html'),
target='hater')}}

The URL() function creates a web2py URL (based on an app, controller, function, args, and vars). You have passed a fully formed URL to the function, which is not how it is intended to be used. Is foo.html part of your web2py app, or is it an external URL? If the latter, just do callback='http://mysite.com/foo.html'.

Anthony

Toby Shepard

unread,
Jul 25, 2012, 11:38:19 AM7/25/12
to web...@googlegroups.com


> {{=A("CLICK ME!!", callback=URL('http://mysite.com/foo.html'
> <http://mysite.com/foo.html'>),
> target='hater')}}
>
> should be
>
> {{=A("CLICK ME!!", callback='http://mysite.com/foo.html'
> <http://mysite.com/foo.html'>,target='hater')}}

Ok, thanks. Perhaps there is a small problem with the
manual section on views. I copied my example from the manual:


{{=A('click me', callback=URL('myaction'), target="t")}}
<div id="t"><div>

and the response of the ajax callback will be stored in the DIV with id
equal to "t".


Tobiah

> which would produce:
>
> <a href="#null"
> onclick="ajax(&#x27;http://mysite.com/foo.html&#x27;,[],&#x27;hater&#x27;);return
> false">CLICK ME!!</a>
>
> and that is what is expected. Perhaps I misunderstand the question.
>
>
> On Tuesday, 24 July 2012 16:21:59 UTC-5, Toby Shepard wrote:
>
> Working through the html helper docs,
> I decided to try the callback parameter
> to the anchor tag:
>
>
> {{=A("CLICK ME!!", callback=URL('http://mysite.com/foo.html'
> <http://mysite.com/foo.html'>),
> target='hater')}}
> {{=DIV(_id = 'hater')}}
>
> foo.html delivers a bit of content. This did not work.
> Viewing the source, I see that the tag was rendered like this:
>
> <a href="#null"
> onclick="ajax(&#x27;/css/edit/http://register.rcsreg.com/foo.html&#x27
> <http://register.rcsreg.com/foo.html&#x27>;,[],&#x27;hater&#x27;);return
>
> false;">CLICK ME!!</a>
>
> That doesn't so good. Am I doing something wrong?
>
> Thanks,
>
> Tobiah
>
> --
>
>
>

Anthony

unread,
Jul 25, 2012, 12:21:57 PM7/25/12
to web...@googlegroups.com
Ok, thanks.  Perhaps there is a small problem with the
manual section on views.  I copied my example from the manual:


{{=A('click me', callback=URL('myaction'), target="t")}}
<div id="t"><div>

and the response of the ajax callback will be stored in the DIV with id
equal to "t".

No, there's no problem with the book. Notice, you didn't copy the example exactly. The example generates the callback URL using the web2py URL() function, which generates web2py URLs. In your code, you passed a fully formed URL (possibly an external URL?) to the URL() function, which is not how it works.

Anthony 

Toby Shepard

unread,
Jul 25, 2012, 12:22:11 PM7/25/12
to web...@googlegroups.com
On 07/24/2012 06:48 PM, Massimo Di Pierro wrote:
> {{=A("CLICK ME!!", callback=URL('http://mysite.com/foo.html'
> <http://mysite.com/foo.html'>),
> target='hater')}}
>
> should be
>
> {{=A("CLICK ME!!", callback='http://mysite.com/foo.html'
> <http://mysite.com/foo.html'>,target='hater')}}

Ok, so now I have:

{{=A("CLICK ME!!", callback='http://mysite.com/foo.html', target='hater')}}
{{=DIV(_id = 'hater')}}

And, viewing the source, I'm getting this:

<a href="#null"
onclick="ajax(&#x27;http://mysite.com/foo.html&#x27;,[],&#x27;hater&#x27;);return
false;">CLICK ME!!</a>
<div id="hater"></div>


Thanks,

Tobiah

Toby Shepard

unread,
Jul 25, 2012, 12:26:53 PM7/25/12
to web...@googlegroups.com
> --
>
>
>

Oh, I had thought that 'myaction' stood for a full URL. So in this
case, is 'myaction' actually the name of a controller, or function?

Thanks,

Toby

Anthony

unread,
Jul 25, 2012, 12:31:02 PM7/25/12
to web...@googlegroups.com
Oh, I had thought that 'myaction' stood for a full URL.  So in this
case, is 'myaction' actually the name of a controller, or function?

It's a function. When you don't pass an application or controller name to URL(), it assumes the current application and current controller.

Anthony 
Reply all
Reply to author
Forward
0 new messages