Adding "dataType" to ajaxGet

15 views
Skip to first unread message

j...@joescii.com

unread,
Sep 28, 2017, 3:59:30 PM9/28/17
to Lift
While testing the work Antonio (yes sir, you did the hard part for rehydrating comets for me to copy) and I have done to make Lift utilize clustered containers, I have discovered I really need to use GET instead of POST in order to fetch the comet IDs when a session gets restored to a new Lift node. However, only ajaxPost has "dataType" as a parameter which I need to set to "html". On the other hand, ajaxGet only does "script" type.

I'd like to add "dataType" as a final optional parameter to ajaxGet, but unfortunately ajaxPost has it as the third argument. Hence our ajaxPost and ajaxGet will have the parameters in different order: 


ajaxPost: function(url, data, dataType, onSuccess, onFailure)

ajaxGet: function(url, data, onSuccess, onFailure, dataType)


I could slap it into the center and do arguments length checking and so forth, but that would make existing code really gross. I feel like having the parameters inconsistent between the two is the lesser of two evils. What say the community? 

Joe


Antonio Salazar Cardozo

unread,
Sep 28, 2017, 4:13:49 PM9/28/17
to Lift
Can you introduce a separate function, perhaps `typedAjaxGet`? I see the conundrum though,
none of the solutions are particularly pretty.
Thanks,
Antonio

Joe Barnes

unread,
Sep 28, 2017, 8:09:35 PM9/28/17
to lif...@googlegroups.com
Yeah, I thought about doing another method too. However, if I go the route of having another method (or perhaps overloading existing), I would probably go the approach of passing an object in so that it'll be safe-guarded against changes in the future: 

ajaxGet: function( { url: "", data: "", onSuccess: "", onFailure: ""} )

Seems to be a common API pattern in the JS world these days from what I hear :) 

Joe


/**
 * Joe Barnes
 * Owner/Principle Consultant, joescii, llc
 */


--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Antonio Salazar Cardozo

unread,
Oct 3, 2017, 12:05:10 PM10/3/17
to Lift
That'd be sweet as well, definitely. Mostly I would keep in mind that `ajaxGet` is public
API as of Lift 3.0.0, so we need to be careful about changing its behavior.
Thanks,
Antonio

Joe Barnes

unread,
Oct 3, 2017, 2:07:47 PM10/3/17
to lif...@googlegroups.com
Understood that it is public. If it wasn't, I'd just toss in the new parameter and forget about it. I'll try the object approach and see how it shakes out.

Joe


/**
 * Joe Barnes
 * Owner/Principle Consultant, joescii, llc
 */


Reply all
Reply to author
Forward
0 new messages