문제

In my app, I have a view that includes this line as part of a table:

<td>{{=A('Callback test', callback=URL('jquery_test'), target=':eval')}}</td>

jquery_test is a method that does this:

def jquery_test():
    return "jQuery('#option_list').html('Example jQuery string');"

This worked in an earlier version of web2py: the string "Example jQuery string" was correctly injected into the view's option_list divison.

This morning, realizing I was way behind on web2py, I upgraded to 2.9.5 stable. Now, the above code redirects the returned string: I get a blank view with "jQuery('#option_list').html('Example jQuery string');" on it. The URL for the page is

"http://127.0.0.1:8000/myApp/default/jquery_test"

I can't say what upgrade changed this behavior, as I went from 2.2-something to 2.9.5. Any ideas what changed and how to correct it?

Thanks.

Edited with some additional information...I have updated the web2py.js (and other .js and .css files as appropriate) as suggested by Anthony below.

Using this callback in the view file:

<td>{{=A('Callback test', callback=URL('jquery_test'), target='options_list')}}</td>

correctly calls the jquery_test method and populates the DIV id='options_list'

Using this callback:

<td>{{=A('Callback test', callback=URL('jquery_test'), target=':eval')}}</td>

does not call the jquery_test method. It never executes at all.

I'm hopeful this provides some additional clues.

도움이 되었습니까?

해결책

When you upgrade the framework, you also have to upgrade the web2py.js file in your application's /static folder, as that is part of the framework code and required for the JavaScript/Ajax functionality to work properly.

UPDATE: Looking at the old and new code, it looks like the implementation has changed. It's true that target=':eval' used to work (due to the behind-the-scenes implementation using the ajax() function), but that was not a documented feature.

As an alternative, instead of having the Ajax action return JavaScript to be evaluated, you should instead be able to add the JavaScript code to response.js, and it will be executed on the client.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top