Do you have a blog_comment_show() action in your controller? On Friday, June 10, 2011 10:58:56 PM UTC-4, 黄祥 wrote:
> thank you so much for your hints, anthony, but, pardon me, the results on > the form components is loading..., the page didn't show an error, but keep > loading..., is there something i missed in my code? > > e.g. > *=== controller ===* > > blog = db.blog > blog_comment = db.blog_comment > blog_comment_blog_id = db.blog_comment.blog_id > blog_comment_active = db.blog_comment.is_active > > def blog_comment_add(): > return __add_2(blog, blog_index, blog_comment, blog_comment_blog_id) > > @auth.requires_login() > def __add_2(table_0, index_link, table_1, field): > page = table_0(request.args(0)) or redirect(URL(index_link)) > field.default = page.id > form = crud.create(table_1, message = T('Record Inserted'), > next = URL(args = page.id)) > *response.js = 'web2py_component(action = "%s", target = "%s")' * > * % (URL('blog_comment_show.load'), * > * 'comments_%s hidden' % page.id)* > return dict(page = page, form = form) > > *=== view ===* > > {{=LOAD('default', 'blog_comment_show.load', args = page.id, ajax = > True)}} > *{{=LOAD('default', 'blog_comment_add.load', args = page.id, * > * target = 'comments_%s hidden' % page.id, ajax = True)}}* > > *=== blog_comment_show.load ===* > > {{if len(results):}} > <span onclick = "jQuery('.comments_{{=page.id > }}').slideToggle('slow');"> > {{=A(T('Comments (%s)' % len(results)), _href = '#')}} > </span> > > <div class = "comments_{{=page.id}} hidden"> > {{for blog_comment in results:}} > {{=SPAN(db.auth_user[blog_comment.created_by].first_name, T(' on > '), > blog_comment.created_on, T(' Said '), > blog_comment.comment)}} > {{=BR()}} > {{=SPAN(blog_comment.like, > _id = 'blog_comment_like_%s' % blog_comment.id)}} > {{=SPAN(T('People Like This'))}} > > <span onclick="jQuery('#id').val('{{=blog_comment.id}}'); > ajax('{{=URL('blog_comment_like.load')}}', ['id'], > 'blog_comment_like_{{=blog_comment.id}}');"> > {{=A(T('Like'), _href = '#')}} > </span> > {{=BR()}} > {{pass}} > </div> > {{else:}} > {{=DIV(B(T('No Comment Posted Yet')))}} > {{pass}} > > *=== blog_comment_add.load ===* > > {{=DIV(A(T('Post a Comment'), _href = '#'), _class = 'post', > _onclick = "jQuery('.form_%s').slideToggle('slow');" % page.id)}} > > {{=DIV(form, _class = 'form_%s hidden' % page.id, > _onsubmit = "ajax('blog_comment_add', [], 'comments_%s hidden');" % > page.id)}} > > On Sat, Jun 11, 2011 at 8:28 AM, Anthony <abas...@gmail.com> wrote: > >> Maybe try having the post comment action return some JS via response.js >> that calls the web2py_component JS function to update the list component: >> >> def post_comment(): >> # do some stuff >> response.js='web2py_component(action="%s",target="%s")' % >> (URL('list_comments.load'), 'comment_list') >> return dict(...) >> >> def list_comments(): >> # code to list comments >> >> In view: >> >> {{=LOAD('post_comment.load', ajax=True)}} >> {{=LOAD('list_comments.load', target='comment_list', ajax=True)}} >> >> >> See >> http://web2py.com/book/default/chapter/13#Client-Server-Component-Communications >> . >> >> Anthony >> >> On Friday, June 10, 2011 8:44:26 PM UTC-4, 黄祥 wrote: >> >>> hi, >>> >>> is ajax can work in components? i mean let say that i separated the >>> comment into 2 components, 1 for list of view comments and the other >>> is form to post the comment. i have a problem when i post the comment >>> using the form, the data that have been posted is not directly change >>> on list of comments (the other components), i must refresh my browser >>> many times so that the list comments can show the latest posted >>> comment. is there any clue or solution to implement ajax that works in >>> other components? >>> >>> any hints, suggestion is greatly appreciate. >>> thank you very much. >> >> >