Life saver, it works, I hope that the document was better, it is somewhat lacking on this area.
Thanks, Yuval On Sunday, May 19, 2013 11:35:23 PM UTC-7, Lio wrote: > > Hi Yuval, > > I was trying to do the same as you passing vars to controller via DIV. The > fact is (as far as I tested), ajax(url, ['name'], 'target') doesn't work > with "_name" of DIV (or <textarea> (or maybe some other tags, to be > tested). The ajax call functions but "request.vars" is empty. You can use > <input> or <select> instead. Assign your value to "_value" of the tag and > give the tag name in ajax. You may set the block hidden by css if the only > function of the block is to pass the var. A piece of example code in "VIEW": > > <input id="pass_value" name="some_value"></input> > <div id="ajax_call">bu la bu la</div> > <div id="target"></div> > > > <script type="text/javascript"> > $(document).on("click", "#ajax_call", function(){ > jQuery(pass_value).val('value_to_controller'); > ajax("{{=URL('ajax_call_function')}}", ['some_value'], 'target'); > }); > </script> > > Hope this helps. > > Lio > > > > 在 2013年5月20日星期一UTC+8上午11时43分54秒,Yuval写道: >> >> I'm trying to pass back a DIV element using Ajax function, the flow >> works, but the argument is not returned into the request.vars. >> >> Using Ajax() on another view works well for me. >> >> *The scenario:* >> >> - SQLFROM.grid element is displayed in the view. >> - When a row is clicked, I'm: >> - capturing the event, >> - getting the row's first cell value, >> - setting the value into a hidden div (selected_job) (work around >> not being able to pass value back by Ajax()) >> - Using Ajax() calling back and passing the selected_job element. >> >> *View:* >> {{extend 'layout.html'}} >> <script type="text/javascript"> >> $(document).ready(function(){ >> $("tr").click(function(){ >> var sid = $(this).find('td').eq(0).text(); >> $(selected_job).text(sid); >> ajax('update_job_items', ['selected_job'], 'job_items_grid'); >> }); >> }); >> </script> >> >> <div id='selected_job' class='hidden'>-1</div> >> {{=jobs}} <!-- Displays an SQLFORM.grid --> >> <div id='job_items_grid' ></div> >> >> *Controller:* >> def update_job_items(): >> print request.vars # ==> <Storage {}> empty.... >> item_id = request.vars.selected_job # item_id ==> NoneType: None >> return DIV('Done') >> >> The above flow works, values are captured correctly, *update_job_items** >> ()* is called but *request.vars* is empty from any element >> >> An advice will be greatly appreciated. >> >> Yuval >> > -- --- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.