1

My problem is, that I need to reload a component which is containing an image by another component. The image is generated by a function/controller and has thus always the same location/URL.

The reload triggered by the second component reloads the first component but doesn't update the image loaded within the first component

Thus, my question is: How can I update/reload the image loaded by the first component?

Thanks for any support!

Regards Clemens

Clemens
  • 33
  • 8
  • Maybe the argument which is passed by the initial load is the problem. Doing some search on the web, I found a solution using web2py_component. But there I get the message 'insufficient privileges' and 'access denied'. Both components use 'user_signature=True' or at least component_1 ... no difference. – Clemens Oct 18 '16 at 14:01
  • I've added an JS-alert to response.js - the alert is shown. But not the update/reload of component_1. As further information: component_1 has a div containing a dynamically create graph very similar to the bg_graph_model() in appadmin.py. Is this the problem, that component_1 is using a further controller/function? – Clemens Oct 18 '16 at 18:31
  • The problem is obviously that the image (generated) is not updated/reloaded when the component is reloaded. Thus, the question could be how to reload an image which is part of a component, since the change of that image is the reason to reload. – Clemens Oct 18 '16 at 21:55
  • Maybe ask on the web2py google group if you get no help here. – Terrence Brannon Oct 18 '16 at 23:43
  • Thanks Terrence. I will follow your advice, if I don't find a solution. But I think, I know the problem. It seems not to be a web2py problem but a jQuery problem. Obviously jQuery is not updating the image as long as it has the same name. Since I'm generating the image by a function call, this is the case. Today I'm gonna evaluate this. If this is the solution I will write it down here. If not, I will switch to the web2py google group ... so thanks again for that tip, Terrence! – Clemens Oct 19 '16 at 09:07

1 Answers1

1

The problem is not a web2py one but a jQuery one. As long as the URL of the image to be reloaded/updated is the same (due to image is generated or updated in place). The solution is to add a dynamically generated extension to the URL e.g. as vars to the image call and to be dropped by the generation:

response.js =  'jQuery("#graph_img").attr("src","%s?"+Date.now());' % URL('default', 'generate_graph', args=['browser','1'])

I came to this solution by the following Stack Overflow post: Refresh image with a new one at the same url

Clemens
  • 33
  • 8