JQuery form sadece bunu gönderin ilk defa çalışmıyor ve ikinci

0 Cevap php

Ben bir veritabanına veri eklemek bir form var. Tüm Gönderdiğiniz bastığınızda yüzden kodu doğrular ve her şeyin doğru olup olmadığını o zaman dışarı sayfayı yenileyerek ile yazılan veri gönderen jquery ve ajax ile yapılır. Sorun formu ilk kez çalışır, ancak form ile başka giriş göndermek için gittiğinizde o çalışmıyor değildir. Ben bir ilgisi var sanıyordum

$(document).ready(function(){

But I really have no idea. I've pasted some of the code below. It is pretty long, but this should give enough info to know what it's doing. The entire js file is at http://www.myfirealert.com/callresponse/js/AddUser.js

$(document).ready(function(){
$('#AddCaller').click(function(e){

    //stop the form from being submitted
    e.preventDefault();

    /* declare the variables, var error is the variable that we use on the end
    to determine if there was an error or not */
    var error = false;
    var Firstname = $('#Firstname').val();
    ...OTHER FORM FIELDS HERE

    /* in the next section we do the checking by using VARIABLE.length
    where VARIABLE is the variable we are checking (like name, email),
    length is a javascript function to get the number of characters.
    And as you can see if the num of characters is 0 we set the error
    variable to true and show the name_error div with the fadeIn effect. 
    if it's not 0 then we fadeOut the div( that's if the div is shown and
    the error is fixed it fadesOut. */


    if(Firstname.length == 0){
        var error = true;
        $('#Firstname_error').fadeIn(500);
    }else{
        $('#Firstname_error').fadeOut(500);
    }
    if(Lastname.length == 0){
        var error = true;
        $('#Lastname_error').fadeIn(500);
    }else{
        $('#Lastname_error').fadeOut(500);
    }
    ...MORE CONDITIONAL STATEMENTS HERE




    //now when the validation is done we check if the error variable is false (no errors)
    if(error == false){
        //disable the submit button to avoid spamming
        //and change the button text to Sending...
        $('#AddCaller').attr({'disabled' : 'true', 'value' : 'Adding...' });

        /* using the jquery's post(ajax) function and a lifesaver
        function serialize() which gets all the data from the form
        we submit it to send_email.php */
        $.post("doadd.php", $("#AddCaller_form").serialize(),function(result){
            //and after the ajax request ends we check the text returned
            if(result == 'added'){

                 //$('#cf_submit_p').remove();
                //and show the success div with fadeIn
                $('#Add_success').fadeIn(500);
                 $('#AddCaller').removeAttr('disabled').attr('value', 'Add A Caller');
                 document.getElementById('Firstname').value = "";
                 document.getElementById('Lastname').value = "";
                 document.getElementById('PhoneNumber').value = "";
                 document.getElementById('DefaultETA').value = "";
                 document.getElementById('Apparatus').value = "";
                 document.getElementById('DefaultLocation').value = "";


                 setTimeout(" $('#Add_success').fadeOut(500);",5000);

            }else if(result == 'alreadythere'){
                                    //checks database to see if the user is already there
                $('#Alreadythere').fadeIn(500);
                $('#AddCaller').removeAttr('disabled').attr('value', 'Add A Caller');
            }
            else{
                //show the failed div
                $('#Add_fail').fadeIn(500);
                //reenable the submit button by removing attribute disabled and change the text back to Send The Message
                $('#AddCaller').removeAttr('disabled').attr('value', 'Send The Message');

            }
        });
    }
});    
});

Şu anda, ilk kez harika çalışıyor formunu kullanın. ve düğme etkinleştirilmesi, ancak başka bir giriş yapmak ve ardından çalıştığınızda sonra düğme hiçbir şey olmuyor.

Yardımın için teşekkürler!

EDIT: formu düğmesi hala etkindir ve bunu tıklayabilirsiniz ilk defa gönderir, ama bunu tıkladığınızda formu doldurunuz bile hiçbir şey olmuyor ... sonra. Formun click olayı ilk defa ateş değil gibi.

EDIT2 istediği gibi, ben HTML göndermek için gidiyorum, bu şifre korumalı bir site arkasında, yani sana sayfası bağlantısını gönderebilirsiniz olamaz.

<form action='addcallers.php' method='post' id='AddCaller_form'>

 <h2>Add Callers</h2>
 <p>
 First Name:
 <div id='Firstname_error' class='error'> Please Enter a First Name</div>
 <div><input type='text' name='Firstname' id='Firstname'></div>
 </p>

 <p>
 Last Name:
 <div id='Lastname_error' class='error'> Please Enter a Last Name</div>
 <div><input type='text' name='Lastname' id='Lastname'></div>
 </p>
 ...MORE FORM FIELDS HERE


 <div style="display:none;">
 <input type='text' name='DefaultLocation' id='DefaultLocation' value= "Sometthing"      readonly=readonly >

 </div>
 </p>

 <p>




 <div id='Add_success' class='success'> The user has been added</div>
 <div id='Alreadythere' class='error'> That user is already in the database</div>
 <div id='Add_fail' class='error'> Sorry, don't know what happened. Try later.</div>
 <p id='cf_submit_p'>
 <input type='submit' id='AddCaller' value='Send The Message'>
 </p>
 </form>  

 </div>

EDIT3 Orada sayfadaki diğer ajax çok, ama düz javascript ile yazılmış. Ben herhangi bir şekilde işlevselliğini etkileyecek emin değilim. Ama gerekirse ben de bu ajax gönderebilirsiniz.

EDIT4 I http://web.enavu.com/tutorials/create-an-amazing-contact-form-with-no-ready-made-plugins/ orijinal öğretici var ve modifiye

EDIT bazı farklı uyarılar koyarak sonra, ben koşullu deyimi if(error==false)... Herhangi bir fikir neden yapmaz öğrendim?

0 Cevap