Sometimes there is a need to call a JavaScript function—to update the UI or for some other reason—depending on the result of some business logic that runs in the server.
If you are not using Ajax, the only way to achieve this is by redirecting the user to add a parameter in the URL, so you can check for its existence and decide whether to call the given function or not. For example, let's say that you need to execute a JavaScript function depending on the parameter foo
. If you are not using Ajax, you'll have to redirect the user to /somePage?foo=valueOfFoo
, and depending on the value of foo
, decide whether your application should execute the JavaScript function or not.
Fortunately, Lift gives us a practical and easy way to accomplish this without the need to redirect the user, and this is what we will learn how to do in this recipe.