thank you so much for corrected my mistook code, anthony, but the results is same now the blog comment show appears loading... First time my incorrect code show the blog comment form page appears loading... and then right now the blog comment show. actually i come from the simple things one (without ajax, jquery, and component) and right now i try to learn and implement both of it's.
any hints, suggestion or references? thank you so much before. On Sat, Jun 11, 2011 at 12:44 PM, Anthony <[email protected]> wrote: > I think you're specifying the target div name in the wrong place. Instead > of: > > {{=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)}} > > I think you want: > > {{=LOAD('default', 'blog_comment_show.load', args = page.id, > target = 'comments_%s hidden' % page.id, ajax = True)}} > {{=LOAD('default', 'blog_comment_add.load', args = page.id, ajax = True)}} > > > Does that change help? > > Also, in __add_2(), you might want to return response.js conditionally, > only when a new comment has actually been added -- otherwise, when the page > first loads, the blog_comment_show() component will be called/load twice > (once because of the LOAD, and once because of the response.js from the > blog_component_add() component). > > If you're still having problems, I recommend creating a simplified version > of the setup just to see if you can get the basic inter-component > communication working -- then add in all the complexity and see where it > breaks down. > > Anthony > > On Saturday, June 11, 2011 12:46:29 AM UTC-4, 黄祥 wrote: > >> yes, i have. >> >> def blog_comment_show(): >> return >> __show_2(blog, blog_index, blog_comment, blog_comment_blog_id, >> blog_comment_active) >> >> @auth.requires_login() >> def __show_2(table_0, index_link, table_1, field, active): >> page = table_0(request.args(0)) or redirect(URL(index_link)) >> results = db((field == page.id) & (active == True)).select(orderby = >> ~table_1.id, >> cache = >> (cache.ram, >> >> 10)) >> return dict(page = page, results = results) >> >> i think the error is on target load, so that my page keep showing >> loading... >> >> did you have any way out for this probelm? >> thank you so much. >> >> On Sat, Jun 11, 2011 at 11:05 AM, Anthony <[email protected]> wrote: >> >>> 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 <[email protected]> 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. >>>>> >>>>> >>>> >>

