0

I follow this tutorial:

http://samsonasik.wordpress.com/2012/10/11/zend-framework-2-using-zend-form-and-ajax/

I dont want to popup in my code so as per above tutorial code call showform action direct by localhost/ajax_demo/public/testajax/skeleton/showform . while submit this form its call validatepostajax function two time means validate two times and also save data into database two times.

Please help me how to prevent it for submit and validate only for one time.

Thanks in Advance..

My ajax form code is:

        $(function(){
        $("form#loginform").submit(function(){

            $.post(url_loginform,
                   { 'username'    : $('input[name=username]').val(),
                     'password'    : $('form#loginform input[name=password]').val(),
                     'agree' : $('form#loginform input[type=checkbox]').val()    
                   }, function(itemJson){
                     $('.error').remove();
                     $('.success').remove();
                    /*Check error exist or not For each form element and set validation messages HTML*/
                    var error = false;
                    if (!error){                     
                        if (itemJson.success == 1){
                            $("#loginform").prepend('<li class="success">Login Successfully</li>');
                        }
                    }
                    /*Invalid Credentials*/
                   if (itemJson.error == 1){
                            $("#loginform").prepend('<li class="error">Invalid Credentials</li>');
                    }

            }, 'json');

            return false;
        });
      });     

This code is developed on reference above link, but it execute two times. so how can i call it only one time.

1 Answer 1

1

This could be related to your JavaScript implementation. You haven't post any code, so i can simply speculate about it.

Maybe you have bound the ajax request multiple times for the click event? (f.e. this issue)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply your link help to solved my issue.so I could improve my code like this $(function(){ $("form#loginform").unbind("submit"); $("form#loginform").submit(function(){ .... }); });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.