Abdulkareem
Abdulkareem

Reputation: 119

how it can be known when LOAD() in web2py is success


I am using LOAD() in a controller as below: def showResult(): msg='' result=LOAD('ResController','res.load',ajax=True) if 'pass' in result: msg='Congratulations, you've passed' response.flash= msg

what I found is this: when the load() invoked (and before it successfully receive the response from res.load) it passes "loading..." to the result variable which in turns affect the if condition.

my question is this: is there any way to make the if condition works after the load() successfully receive the response?

Upvotes: 0

Views: 42

Answers (1)

Anthony
Anthony

Reputation: 25536

You are misunderstanding how LOAD works. It is simply an HTML helper that generates an HTML div that includes special attributes that trigger Javascript in the browser when the containing page loads (the Javascript makes an Ajax call to the specified action, which then returns a response to the browser). It does not execute an HTTP request inside your controller code and return a response there, so you cannot do anything with the Ajax response in the controller that generates the LOAD helper.

Note, LOAD returns a DIV helper, and HTML helpers act like lists with respect to their components. Because the DIV is initiated with the text "Loading...", it acts as if it is a list like ['Loading...']. So, when you do if 'pass' in result, the condition will always be False.

To get further help, you probably have to clarify exactly what the workflow should be and what is happening in ResController/res. Perhaps that action is the one that needs to return a flash message to the browser.

Upvotes: 1

Related Questions