Ajax Jquery Submit validation page data __jquery

Source: Internet
Author: User
Tags prev
$ (function () {//id array to check for empty input boxes var nullcheckarray = new Array ("username", "password", "t
    El ");

    The ID array of the input box that needs to check the array type var numbercheckarray = new Array ("Age", "Sex", "tel");
        $ ("#submit"). Click (function () {//Check for empty checknull (Nullcheckarray);
        Check the number type CheckNumber (Numbercheckarray);
    Submit Data Userinfopost (/user/add.do);

    }); Check if the input box is an empty function checknull (idlist) {if (idlist!= null && idlist.length > 0) {for (VA
                    R i = 0;i < idlist.length;i++) {var elem = $ ("#" +idlist[i]);
                    var val = elem.val ();
                        if ($.trim (val) = "") {alert (Elem.prev (). text+ "cannot be empty!");
                    return false;
        } return true;
        }else{return false; }//Listen for input box input type function CheckNumber (idlist{if (idlist!= null && idlist.length > 0) {for (var i = 0;i < idlist.length;i++) {
                var Elem = $ ("#" +idlist[i]);
                    Loss of focus event Elem.blur (function () {var val = elem.val ();
                        if (!$.isnumeric (val)) {alert (elem.prev.text+ "is a numeric type");
                    return false;
            }
                });
        return true;
        }else{return false;
    The value function V (ID) {return $.trim ($ ("#" +id) of an INPUT element is obtained by ID. Val ());
        }//Submit user Information function Userinfopost (URL) {//value var username = V ("username");
        var password = V ("password");
        var age = V (' age ');
        var sex = V ("Sex");
        var tel = V ("tel"); Package JS Object var userInfo = {"username": username, "password": Password, "age" : Age, "Sex ": Sex," tel ": Tel,};  Submit $.ajax ({type: Post), Url:url, Data:userinfo, success:
            function (data) {//Receive server return value alert (data); Set the text box not editable $ (". User-info Input[type=text]"). each (function () {$ (this). attr ("ReadOnly", "readonl
                Y ");
            $ (this). attr ("Disabled", "disabled");
            });
            Displays a div $ ("#div1"). CSS ("Display", "block");
            Hides a div $ ("#div2"). CSS ("display", "none");
    }
        }); }
});
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.