javascript - How update html img src from spring controllers method? -


i add capcha jsp page (kaptcha library). this

@requestmapping(value = "/captcha.jpg", method = requestmethod.get)     public void captcha(httpservletrequest req, httpservletresponse resp) throws servletexception, ioexception {         super.captcha(req, resp);     } 

and in page

<img src="captcha.jpg"/> 

now need create button update captcha.(or when clik captcha image)

i tried this

<a href="captcha.jpg">             <img src="captcha.jpg"/>             </a> 

but when click image open singly. need refresh captcha image after click.

maybe javascript, maybe else? how it?

update

i create

<script>                 function update() {                     document.getelementbyid('my-image').setattribute('src', "captcha.jpg");                 }             </script>             <a href="" onclick="update()">                 <img src="captcha.jpg" id="my-image"/>             </a> 

it work after img update page scroll up. how can fix it?

your page scrolling because default behavior of anchor tag scroll top unless give url, element scroll to, or javascript: statement.

to fix it, either put javascript: inside the href of anchor tag, or remove anchor tag , put onclick event on image this:

<img src="captcha.jpg" id="my-image" onclick="update()" /> 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -