Pradeeshnarayan
Pradeeshnarayan

Reputation: 1235

Web2py ajax ':eval' action is not returning HTML functions

In my ajax function call am using target ':eval' to do some actions from controller. And my controller function returns value with web2py HTML functions def ajaxmessage(): return "jQuery('#divAjaxTest').html(%s);" % repr(H1('ajax message')) #not returning any value.

But if it is just a text with repr() then it is returning fine. return "jQuery('#divAjaxTest').html(%s);" % repr('ajax message'). #this is working fine

I am new to web2py, may be it is a small problem. Please let me know how to solve this. Thanks in advance.

Upvotes: 1

Views: 751

Answers (1)

Anthony
Anthony

Reputation: 25536

The first one should return a value, but the generated string would be something like:

jQuery('#divAjaxTest').html(<gluon.html.H1 object at 0x153ccd0>)

repr() is not the right function for serializing web2py HTML helpers -- instead you should use str(H1('ajax message')) or H1('ajax message').xml(). You probably also need to surround the string with quotes in the Javascript code:

def ajaxmessage():
    return "jQuery('#divAjaxTest').html('%s');" % H1('ajax message').xml()

Upvotes: 1

Related Questions