Play With Liftweb’s AJAX Generators using Scala

Table of contents
Reading Time: 2 minutes

AJAX is an approach for building dynamic web content on the client side . In Liftweb , we can implement this approach either by AJAX or by Comet . Comet is like AJAX , except in opposite direction .
AJAX model increases the richness of the User Experience for a single client at a time, Comet can do the same for multiple users.
First thing , I want to point out here is that AJAX generators take callback methods just like regular element generators. The only Difference is that when we call SHtml generator , it always returns SHtml.any . On the other way , when we call AJAX , it must returns a net.liftweb.http.js.JsCmd. The reason is that the return from the callback is itself a client-side callback that can be used to update the client content.

Let’s have a look at some AJAX generators :

1) ajaxButton : Renders a button that will submit an AJAX request to server .

2) ajaxText : Renders an input text element that will send an AJAX request on blur.

This is very useful when you want to get text box value , once user hits enter key .

3)ajaxCall: Renders the JavaScript code that will submit an AJAX request but it will also send the value returned by the JsExp provided.

In jsCalcValue , you can get only one html element value by id using JE.ValById(“test”) and pass this value to java script function .

4)ajaxInvoke: Similar to ajaxCall but there is no value to be computed and sent to the server

5)ajaxRadio: Renders a radio element then sends an AJAX call when the value changes

6)ajaxSelect: Renders a select element then sends an AJAX call when the value changes

7)ajaxCheckbox: Renders a checkbox element that when clicked will send an AJAX call

8)ajaxForm: Wraps a NodeSeq that represents the form’s content and makes an AJAX call when the form is submitted.

9)makeAJAXCall: Renders the JavaScript code that will submit an AJAX request

Written by 

Ayush is the Sr. Lead Consultant @ Knoldus Software LLP. In his 10 years of experience he has become a developer with proven experience in architecting and developing web applications. Ayush has a Masters in Computer Application from U.P. Technical University, Ayush is a strong-willed and self-motivated professional who takes deep care in adhering to quality norms within projects. He is capable of managing challenging projects with remarkable deadline sensitivity without compromising code quality.

1 thought on “Play With Liftweb’s AJAX Generators using Scala3 min read

Comments are closed.