I have this code, in the initial view shows the elements of the table
service with a json call, i want whenever insert a new element in the
form of form.html view (the view form.html is a popup window) re-make
the json call and refresh the initial view, i tried several variations
and all have failed me, anyone have a similar example??? or any
idea???

db.define_table('service',
   Field('name'))

controller.py................................................

def index():
   return dict()

def form():
 
form=FORM(INPUT(_name='name',requires=IS_NOT_EMPTY()),INPUT(_type='submit'))

   if form.accepts(request.vars, session):
      db.service.insert(name = form.vars.name)
   return dict(form=form)


@service.json
def hello():
   l = []
   for row in db(db.service.id > 0).select():
         l.append(row.name)
   return l

//-------------------------------------------------------------------------------------------

index.html..............

{{extend 'layout.html'}}

<label class='link' style='color:green'>+</label>

<div id='target'>

</div>

<script>
jQuery('.link').click(function(){popup("{{=URL(r=request,
f='form')}}")});

jQuery.getJSON("{{=URL(r=request,f='call',args=['json','hello'])}}",
       function(msg){
          jQuery.each(msg, function(){ jQuery("#target").append(this
+ "<br />"); } )
       }
 );


</script>

form.html....................

{{extend 'layout.html'}}
{{=form}

Reply via email to