On Apr 20, 7:01 am, selecta <[email protected]> wrote:
> I found out that if the java scrip files (.js files) are loaded in the
> initial load of the page the embedded javascript of the ajax loaded
> pages is executed
> e.g.
> default.py
> def index():
>  response.files.append(URL(request.application,'static/jquery-
> autocomplete','jquery.autocomplete.pack.js'))
>  response.files.append(URL(request.application,'static/jquery-
> autocomplete','jquery.autocomplete.css'))
>  response.files.append(URL(request.application,'static/jquery-
> autocomplete','jquery.autocomplete.pack.js'))
>  response.files.append(URL(request.application,'static/jquery-
> autocomplete/lib','jquery.bgiframe.min.js'))
>  response.files.append(URL(request.application,'static/jquery-
> autocomplete/lib','jquery.dimensions.js'))
>  return dict()
>
> def test():
>  form = form_factory(Field('myfield'))
>  script = SCRIPT('''$(document).ready(function(){
> $("#no_table_myfield").autocomplete(["a","b"]);});''')
>
>  return TAG[''](form, script)
>
> default/index.html
>  LOAD('default', 'test', ajax=True)
>
> this works

It works but it will work only once, on initial load, which is fine
for this case.
If you need to run some JS every time then don't enclose it inside a $
().ready function, that way it will be executed on every ajax call, at
least it does in my tests with Firefox.
Note that if you remove the ready function around the autocomplete
selection code above it will still work.

> in additioin to that I read that the ajax function can load
> javascrips ... this could mean that something along the lines of
>  script = SCRIPT('''$(document).ready(function(){
> jQuery.ajax(url: "%s")
> $("#no_table_myfield").autocomplete(["a","b"]);});'''%URL(request.application,'static/jquery-
>
> autocomplete','jquery.autocomplete.pack.js'))
>
> could fix some problems, I did not try it out yet since I spend too
> much time already figuring out the first issue


-- 
Subscription settings: http://groups.google.com/group/web2py/subscribe?hl=en

Reply via email to