Hi,
I have had a look at LOAD and Ajax and tested, which I think could work,
the only thinkgI can't get right is to get the data back into the div I
want.
I tried the following {{=LOAD('default','post.load',target='comments',
ajax=True)}} thinking that the data would be put into the target div
specified, with target = 'comments'. When I looked in the source of the
page it shows the following:-
div data-w2p_remote="/music_server/default/post.load/comments" id="
c559498745475">loading...</div>div id = 'comments'></div>
As you see it makes a new div called comments ,but does not put the data in
the original div called comments, is their a way of doing this.
Thanks again.
On Monday, 23 March 2015 16:20:06 UTC, LoveWeb2py wrote:
>
>
> http://web2py.com/books/default/chapter/29/12/components-and-plugins#Components--LOAD-and-Ajax
>
> On Monday, March 23, 2015 at 12:19:34 PM UTC-4, LoveWeb2py wrote:
>>
>> Wouldn't a LOAD/Ajax combo work better in this case and then just include
>> it in your page?
>>
>> On Monday, March 23, 2015 at 8:41:18 AM UTC-4, Garry Smith wrote:
>>>
>>> Hi thanks for the reply.
>>>
>>> What I was trying to do in the original code was return the data to a
>>> div not to a specified page, so what you are saying is correct.
>>> The part about the table, is that it seems to only iterate over the
>>> first record, maybe the code is different for tables, because it has to
>>> iterate for each row and data.
>>> Not sure how to solve at the moment, I'm new to web2py, I'm use to MVC
>>> in Php with codeigniter, so its a bit off a learning curve, especially with
>>> jquery and ajax.
>>> With codeigniter I could send back, Jquery back through with html, which
>>> was then embedded into the page and would just work.
>>> So on to the next part of learning python and web2py.
>>>
>>> Thanks for your reply.
>>>
>>> On Sunday, 22 March 2015 20:45:18 UTC, Anthony wrote:
>>>>
>>>> Just to clarify the original problem, when a controller action returns
>>>> a dictionary (as in your original code), web2py assumes it should then
>>>> look
>>>> for an execute a view. If a dedicated view does not exist for the action,
>>>> it will default to generic.html (though this is disabled by default,
>>>> except
>>>> for local requests in the welcome app). So, you should either create a
>>>> view
>>>> that generates the HTML you want based on what is returned in the
>>>> dictionary, or you should not return a dictionary.
>>>>
>>>> Instead of a dictionary, you can directly return HTML as a string
>>>> (which is what your new code does) by applying the .xml() method to the UL
>>>> helper. However, you don't actually need to apply the .xml() method,
>>>> because if you return an HTML helper object, web2py will automatically
>>>> serialize it to a string for you.
>>>>
>>>> As for returning an HTML table rather than a UL, there's no reason you
>>>> couldn't do that instead. Just create a TABLE object and return that.
>>>>
>>>> Anthony
>>>>
>>>> On Saturday, March 21, 2015 at 8:17:06 PM UTC-4, Garry Smith wrote:
>>>>>
>>>>> Hi with your help I have manage to get the links working using the
>>>>> following code:-
>>>>>
>>>>> def artist():
>>>>>
>>>>> rows = db().select(db.media.artist,db.media.id, groupby =
>>>>> db.media.artist)
>>>>>
>>>>> links = map(lambda row:A(row.artist,
>>>>> callback=URL('album',vars=dict(id=row.id)), target='album'), rows)
>>>>>
>>>>> test = UL([LI(link) for link in links]).xml()
>>>>>
>>>>> return test
>>>>>
>>>>> This now returns the links in a list.
>>>>> Would off like it in a table, but it only returns first record, not
>>>>> sure how I could itterate to return the table rows.
>>>>>
>>>>> Thanks again
>>>>>
>>>>> On Saturday, 21 March 2015 18:19:02 UTC, Garry Smith wrote:
>>>>>>
>>>>>> Hi
>>>>>> I'm trying to return the some links to a div. I have made links with
>>>>>> some information from the database and using the A htlm helper.
>>>>>> The problem I am having is getting the data back correctly, I am
>>>>>> getting the links back correctly, but I am being sent a full web page
>>>>>> with
>>>>>> the links, which is then put in the div.
>>>>>>
>>>>>> *VIEW*
>>>>>> this is link which is sent to the artist page, which gets all the
>>>>>> distinct artist.
>>>>>>
>>>>>> {{=A('click' , callback=URL('artist'), target="artist")}}
>>>>>>
>>>>>> *CONTROLLER*
>>>>>>
>>>>>> This is the controller that makes the links and returns to the div as
>>>>>> specified in above link.
>>>>>>
>>>>>> def artist():
>>>>>> rows = db().select(db.media.artist,db.media.id, groupby =
>>>>>> db.media.artist)
>>>>>>
>>>>>> links = []
>>>>>>
>>>>>> for row in rows:
>>>>>> a = str(row.id)
>>>>>> b = 'album?id='
>>>>>> c = b+a
>>>>>> l = row.artist
>>>>>> f = A(l , callback=URL(c), target="album")
>>>>>> links.append(f)
>>>>>>
>>>>>> return dict(links=links)
>>>>>>
>>>>>> I have tried diffrent ways to solve this, but to no avail, all I want
>>>>>> is to return the links to div.
>>>>>>
>>>>>> What i am trying to do is rewrite a media player, which I wrote in
>>>>>> php a few years ago, but I am having few issues writing a returning
>>>>>> links
>>>>>> on the sly.
>>>>>>
>>>>>> Thanks in advance for any help.
>>>>>>
>>>>>>
>>>>>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.