开发者

Page refresh with onclick event in dojo and I don't want a page refresh

开发者 https://www.devze.com 2023-01-17 03:25 出处:网络
For some reason in IE8 when I run this function after an onclick event it causes a page refresh. I don\'t wan the page refresh to happen.

For some reason in IE8 when I run this function after an onclick event it causes a page refresh. I don't wan the page refresh to happen.

   var edealsButton = dojo.byId("edeals_button");
   var edealEmailInput = dojo.byId("edeals_email");
   var edealsSignup = dojo.byId("edeals_signup");
   var edealsThankYou = dojo.byId("edeals_thankyou");
   var currentValue = dojo.attr(edealEmailInput, 'value');
   if (currentValue != '' && currentValue != 'Enter your email') {
       var anim = dojox.fx.flip({
           node: edealsSignup,
           dir: "right",
           duration: 300
       })
       dojo.connect(anim, "onEnd", this, function() {
           edealsSignup.style.display = "none";
           edealsThankYou.style.display = "block";
       })
       dojo.connect(anim, "onBegin", this, function() {

           var criteria = { "emailAddress": '"' + currentValue + '"' };
           alert("currentValue " + currentValue);
           var d = essentials.CallWebserviceMethod('AlmondForms.asmx/SignupEdeal', criteria);
           d.addCallback(function(response) {
               var obj = dojo.fromJson(response);
               alert(obj.d);
               if (obj != null && obj.d != null) {
                   //alert(obj.d);
                   if (obj.d == false)
                   {
                       var edealSuccess = dojo.byId("edeals_succes_thankyou");
                       var edealError = dojo.byId("edeals_error_thankyou");

                       alert("edealError: " + edealError);
                       dojo.style(edealSuccess, "display", "none");
                       dojo.style(edealError, "display", "inline-block");
                   }
                   else
                   {
                       var edealSuccess = dojo.byId("edeals_succes_thankyou");
                       var edealError = dojo.byId("edeals_error_thankyou");

                       dojo.style(edealSuccess, "display","inline-block");
                       dojo.style(edealError, "display", "none");
                   }
               }
               else {
                   var edealSuccess = dojo.byId("edeals_succes_thankyou");
                   var edealError = dojo.byId("edeals_error_thankyou");

                   dojo.style(edealSuccess, "display", "none");
                   dojo.style(edealError, "display", "inline-block");
               }
           });
       })
       anim.play();
       edealEmailInput.innerHTML == 'Enter your email';
   } 
   else 
   {
       dojo.attr(edealEmailInput, 'value', 'Enter your email');
       dojo.style(ed开发者_运维技巧ealEmailInput, 'color', '#CC2525');
   }


It looks like your "d.addCallback" code might not be disposed of properly. You might want to try placing "dojo.stopEvent()" possibly before the "anim.play();" line and see if this would stop the postback.

From the api.dojotoolkit.org site, the dojo.stopEvent() "prevents propagation and clobbers the default action of the passed event". From the docs.dojocampus.org site, they say that "dojo.stopEvent(event) will prevent both default behavior any any propagation (bubbling) of an event."

Good luck, and hope this helps you out some.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号