>
> In the book example, response.ajax (which should be response.js) is set in 
>> the edit_items() function, which is always called as an Ajax component. You 
>> are setting it in your view() function, but I can't see where that function 
>> is actually called, so I don't know if it is being called as an Ajax 
>> component or as a regular web page.
>
>
> [[NB: To avoid confusion, in the code (included below) I've updated this 
> function name to be viewPatient().]]  
> This viewPatient() function is set as the webGrid.crud_function property, 
> within my index() function of default.py.... 
> (grid.crud_function = 'viewPatient'). I believe the answer to your 
> question is that it is called as a regular webpage, 
> as webGrid is not an ajax component.
>

OK, in that case, setting response.js in viewPatient() won't have any 
effect (by the way, Python prefers view_patient rather than camel case for 
functions and variables -- 
http://www.python.org/dev/peps/pep-0008/#prescriptive-naming-conventions). 
If viewPatient() is simply called as a regular full web page, then to run 
some JS on the page when it loads, you'll have to add a script element with 
the JS code inside a jQuery document ready. In this case, though, that's 
not necessary because it appears you simply want to load a web2py Ajax 
component on that page, which you can simply do by including the LOAD() 
helper in the viewPatient view.

More generally, it does not appear that what you are trying to do exactly 
mirrors the structure of the book example you are copying, so you might be 
better off ignoring that example. Instead, be sure to read 
http://web2py.com/books/default/chapter/29/12#Components. The cookbook is 
generally more advanced and assumes a firm understanding of how the 
framework works. Attempting to alter the examples without understanding the 
underlying functionality is not likely to be a fruitful approach.

Yes. Since reading your comments, and looking at the page-source for the 
> (successful) initial index page upload, I've updated this to:
>
> response.js = \
>   
> 'web2py_component("/ICC_Data_Management/default/post.load?scanId=4","patient");'
>  
> \
>   % URL('/ICC_Data_Management/default/post.load?scanId=4') 
>
> ... and this returns the error:   '<type 'exceptions.SyntaxError'> not 
> enough information to build the url'
>

You are passing a fully constructed url to the URL() function -- that's not 
how it works. You probably want:

response.js = 'web2py_component("%s", "patient");' % URL('default', 
'post.load', vars=dict(scanId=4))

But as mentioned above, response.js isn't really appropriate in this case.

+ to answer the question from Andrew, in a seperate message: 
> ---'Also, I don't see a div with an Id = patient.  That's your target.   
> Is it in the code but not in your post?'
>
> From the example in the book, it appears (to me) to imply that the 
> '{{=LOAD('default', 'list_items', ajax=True, target='showItems')}}' call in 
> the html, automatically creates a div id='showItems'.  This was further 
> evidenced by my own application, where I do not explicitly create a div tag 
> with id=patient, but when I view pagesource for my opening page (which 
> works OK) and has the call  
> {{ 
> =LOAD('default','post.load',ajax=True,target='patient',vars={'scanId':1}) 
> }}, the resulting page source does include a '<div 
> id="patient">loading...</div>' element.
>

Yes, this is correct. If you call LOAD() without specifying a target, it 
will generate a div with a random id, but if you specify a value for 
target, it will use that value as the id for the div it generates. Note, if 
you just call web2py_component() by itself on the client side, it will not 
generate the div for you, so the div must already exist on the page in that 
case (the LOAD() helper is executed on the server side when the page is 
first requested and generates the div at that time).

Anthony

Reply via email to