Lift session valid ajax callback from a static javascript

Posted by ChrisJamesC on Stack Overflow See other posts from Stack Overflow or by ChrisJamesC
Published on 2012-11-17T10:56:20Z Indexed on 2012/11/17 11:01 UTC
Read the original article Hit count: 180

Filed under:
|
|

I am currently implementing a graph visualisation tool using lift on the server side and d3 ( a javascript visualisation framework) for all the visualisation. The problem I have is that in the script I want to get session dependent data from the server.

So basically, my objective is to write lift-valid ajax callbacks in a static js script.

Here is what I tried so far:

What I have tried so far

If you feel that the best solution is one that I already tried feel free to post a detailed answer telling me how to use it exactly and how it completely solves my problem.

REST interface

Usually what one would do to get data from a javascript function in lift is to create a REST interface. However this interface will not be linked to any session. This is the solution I got from my previous question: Get json data in d3 from lift snippet

Give function as argument of script

Another solution would be to give the ajaxcallback as an argument of the main script called to generate my graph. However I expect to have a lot of callbacks and I don't want to have to mess with the arguments of my script.

Write the ajax callback in another script using lift and call it from the main script

This solution, which is similar to a hidden text input is probably the more likely to work. However it is not elegant and it would mean that I would have to load a lot of scripts on load, which is not really conveniant.

Write the whole script in lift and then serve it to the client

This solution can be elegant, however my script is very long and I would really prefer that it remainss static.

What I want

On client side

While reviewing the source code of my webpage I found that the callback for an ajaxSelect is:

<select onchange="liftAjax.lift_ajaxHandler('F966066257023LYKF4=' + encodeURIComponent(this.value), null, null, null)" name="F96606625703QXTSWU" id="node_delete" class="input">

Moreover, there is a variable containing the state of the page in the end of the webpage:

var lift_page = "F96606625700QRXLDO";

So, I am wondering if it is possible to simulate that my ajaxcall is valid using this liftAjax.lift_ajaxHandler function. However I don't know the exact synthax to use.

On server side

Since I "forged" a request on client side, I would now like to get the request on client side and to dispatch it to the correct function. This is where the LiftRules.dispatch object seems the best solution: when it is called, all the session management has been made (the request is authentified and linked to a session), however I don't know how to write the correct piece of code in the append function.

Remark

In lift all names of variables are changed to a random string in order to increase the security, I would like to have the same behavior in my application even if that will probably mean that I will have to "give" the javascript these values. However an array of 15 string values is still a better tradeoff than 15 functions as argument of a javascript function.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about AJAX