简体   繁体   中英

after Ajax function javascript does not work

I have a javascript validation, that checks if input value is empty. Now I want to add a validation, that a special input is not repeating. I wrote a php function for it and also ajax. Ajax works fine, means when I enter a value, that alrady exists in database, it alerts "This No already exists". But after that function call no javascript works.

Here is the code:

function checkValue(valdata){
                    $.ajax({             
                        type: "POST",
                        url:"success.php",
                        cache: false,
                        contentType: false,
                        processData: false,
                        data: valdata,
                        success: function (data) {
                          if(data == 1){
                            alert ("This No  already exists. ");                             
                            return false;
                          }
                        }   
                    });         
                    return true;
                }


                if(document.getElementById("selectErrorcat").value=="selectcategory")
                {
                    alert ("Please select Category");
                }
                else if(document.getElementById("No").value ==="")
                {
                    alert ("Please enter MLS No field");
                }

                else if(document.getElementById("mlsNo").value !=="" ){

                    checkValue(formdata);
                }


                else if(document.getElementById("title_en").value ==="")
                {
                    alert ("Please enter Property Title EN field");
                }

After checkValue(formdata); javascript does not work. What is the problem?

Add an error handler :

success: function (data) {
    if(data == 1){
        alert ("This No  already exists. ");                             
        return false;
    }
},
error : function (jqXHR, textStatus, errorThrown) {
    alert(errorThrown);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM