tags:

views:

150

answers:

2
+2  Q: 

jquery load method

I am using mscaptcha image and trying to only reload the captcha image on button click. Seems like the captcha image is being loaded twice sometimes.

 <script type="text/javascript">
        $(document).ready(function() {
            $('#btnSubmit').click(function() {
                $('#dvCaptcha').load('default.aspx #dvCaptcha');                
            });
        });
  </script>

<div id="btnDiv">
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</div>

<div id="dvCaptcha">
    <cc1:CaptchaControl ID="ccJoin" runat="server" CaptchaBackgroundNoise="none"  CaptchaLength="5" CaptchaHeight="60" CaptchaWidth="200" CaptchaLineNoise="None" CaptchaMinTimeout="5" CaptchaMaxTimeout="240"  />
</div>

Any ideas?

A: 

I'm not all too familiar with asp, but from the top of my head I can think that maybe if you add a "return false" will keep the browser from doing anything unexpected.

Try this:

$('#btnSubmit').click(function() {
    $('#dvCaptcha').load('default.aspx #dvCaptcha');
    return false;     
});

Hope this helps!

jnkrois
what I mean is: on refresh button single click...sometimes there are two images being loaded one after another. sometimes it loads image one time.Also if I return false it wouldnt prevent the user from clicking the refresh button more than once.
A: 

If the problem is related to clicking the submit button more than once, then disable it until the response is received:

 <script type="text/javascript">
        $(document).ready(function() {
            $('#btnSubmit').click(function() {
                $(this).attr("disabled", "disabled");
                $('#dvCaptcha').load('default.aspx #dvCaptcha', function() {
                    $('#btnSubmit').removeAttr("disabled");
                });   
                return false;             
            });
        });
  </script>
karim79
karim,I am using .net app and seems like I have to use $("[id$=btnSubmit]") instead of $('#btnSubmit') to get reference to btnSubmit. so I modified the sample code you mentioned to $(document).ready(function() { $("[id$=btnSubmit]").click(function() { $("[id$=dvCaptcha]").load('Default.aspx [id$=dvCaptcha]'); return false; }); });looks like something wrong the load method syntax. the click event is firing correctly.
pls disregard my previous posts. After bit research found out that$('#dvCaptcha').load('default.aspx #dvCaptcha'); is loading the image but only one time. Maybe its caching the image???