The best way to handle it is to add a return false in the onclick.
Example:
<script>
function DoStuff() { alert('ajax stuff here'); }
</script>
<input type='submit' onClick='DoStuff(); return false;' />
Or add the function to the onsubmit event handler, would work even
better.
On Sep 20, 8:13 pm, cricket <[email protected]> wrote:
> On Mon, Sep 20, 2010 at 1:49 PM, Dave Maharaj <[email protected]> wrote:
> > This is my rough js
>
> > Click submit nothing, click again it submits, click again it submits twice,
> > again submits 3 times…you get the picture. And while its sent to the server
> > you can continue to click away adding to the requests in multiples.
>
> > Anyone see where I am going wrong here?
>
> > <script type="text/javascript">
> > $("#PromotionRequestForm").submit( function() {
> > promo("#PromotionRequestForm", "#promo")
> > //alert('clicked');
> > return false;
> > });
>
> > function promo(selector, target){
>
> > var $form = $(selector);
> > var $target = $(target);
>
> > $form.submit( function() {
>
> > var form_url = $form.attr('action');
> > var form_target = $(target);
> > var form_data = $form.formSerialize();
>
> > $form.ajaxSubmit({
> > type: "post",
> > url: form_url,
> > data: form_data,
> > dataType: 'json',
> > success: function(response){
>
> > if (response.status === true) {
> > alert(response.status);
> > } else {
> > alert(response.status);
> > }
> > }
> > });
> > return false;
> > });
> > };
>
> > </script>
>
> Disable the submit button, then re-enable it in your success callback.
> IIRC, you can disable it in either beforeSerialize or beforeSubmit.
>
> $(SELECTOR).attr.('disabled', true);
>
> > I have googled and tried various bind unbind with no success. (Ajax
> > Submitted form)
> > e.preventDefault();
>
> > Sure all that’s is good stuff but something simple like
> > isSubmitted = false;
>
> > submit form
> > isSubmitted = true;
>
> > then while waiting for response if pressed again do nothing if submitted =
> > true
> > after response set isSubmitted back to false….
>
> The reason those won't work is that your function is being called
> separately on each submit event.
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en