what is difference between ajax() and web2py_component() ?

212 views
Skip to first unread message

Ariya Owam-aram

unread,
Jan 7, 2016, 8:43:40 AM1/7/16
to web2py-users
Hi everyone,

I often use ajax and web2py_component for onclick action (for example) but I never know what is difference between them and how to use them the right way.  Can anyone guide me a good example, please?

Thank your
Ariya


Anthony

unread,
Jan 7, 2016, 10:57:35 AM1/7/16
to web2py-users
The ajax() function provides basic functionality for making an Ajax request, with some additional features, such as automatically sending values from named input fields and inserting the returned data into a particular target within the DOM (or optionally executing some returned Javascript code).

web2py_component (which is a backward compatible alias for $.web2py.component) is a more sophisticated facility for embedding the output of controller actions within web pages. It is much like a page within a page, with the ability to load new content into the component. In particular, it is possible to trap both links and forms, so when you click a link or submit a form contained within a component, the new content will be loaded within the component (without reloading the rest of the page). Components also include functionality to automatically refresh themselves at a fixed interval.

Anthony

Fabiano Almeida

unread,
Jan 7, 2016, 11:57:33 AM1/7/16
to web...@googlegroups.com
Great!

Can you show me examples of using web2py_component?

thanks!

Fabiano.

--
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 web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anthony

unread,
Jan 7, 2016, 12:23:47 PM1/7/16
to web2py-users
You would generally use the LOAD helper -- see http://web2py.com/books/default/chapter/29/12/components-and-plugins#Components--LOAD-and-Ajax.

From Javascript, you can also do:

$.web2py.component("{{=URL('mycontroller', 'mycomponent.load')}}", "target_div");

Which will load the component in an existing div whose id is "target_div".

Anthony


On Thursday, January 7, 2016 at 11:57:33 AM UTC-5, Fabiano Almeida wrote:
Great!

Can you show me examples of using web2py_component?

thanks!

Fabiano.
2016-01-07 13:57 GMT-02:00 Anthony:
The ajax() function provides basic functionality for making an Ajax request, with some additional features, such as automatically sending values from named input fields and inserting the returned data into a particular target within the DOM (or optionally executing some returned Javascript code).

web2py_component (which is a backward compatible alias for $.web2py.component) is a more sophisticated facility for embedding the output of controller actions within web pages. It is much like a page within a page, with the ability to load new content into the component. In particular, it is possible to trap both links and forms, so when you click a link or submit a form contained within a component, the new content will be loaded within the component (without reloading the rest of the page). Components also include functionality to automatically refresh themselves at a fixed interval.

Anthony


On Thursday, January 7, 2016 at 8:43:40 AM UTC-5, Ariya Owam-aram wrote:
Hi everyone,

I often use ajax and web2py_component for onclick action (for example) but I never know what is difference between them and how to use them the right way.  Can anyone guide me a good example, please?

Thank your
Ariya


--
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 web2py+unsubscribe@googlegroups.com.

Ariya Owam-aram

unread,
Jan 7, 2016, 7:38:43 PM1/7/16
to web2py-users
Hi Anthony,

Thank you for your clear and helpful explanation. I still have a question, what is .load is for? Why do I need to specific view extension to .load?  Sometime I use .html for LOAD() or web2py_component() but did't see the difference.

Thank you again
Ariya

เมื่อ วันศุกร์ที่ 8 มกราคม ค.ศ. 2016 0 นาฬิกา 23 นาที 47 วินาที UTC+7, Anthony เขียนว่า:
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

Anthony

unread,
Jan 7, 2016, 10:46:04 PM1/7/16
to web2py-users
.load is just a convention to help distinguish from a full HTML page, but you can use any extension you want. In some cases, the same controller might be used as both a component and a full web page, so you could have separate .load and .html views for that controller.

Anthony

Ariya Owam-aram

unread,
Jan 8, 2016, 10:37:27 AM1/8/16
to web2py-users
Thank you,

Ariya

เมื่อ วันศุกร์ที่ 8 มกราคม ค.ศ. 2016 10 นาฬิกา 46 นาที 04 วินาที UTC+7, Anthony เขียนว่า:
Reply all
Reply to author
Forward
0 new messages