Article From:https://www.cnblogs.com/beast-king/p/9123178.html
<script type="text/javascript">
            mui.init();

            var dom_login_btn = document.getElementById("login");
            dom_login_btn.addEventListener('tap', function(e) {
                var cname = document.getElementById("account").value.trim();
                var pwd = document.getElementById("password").value.trim();
                if(cname.trim().length == 0) {
                    mui.toast("The username is not empty! ")
                    return;
                } else if(pwd.trim().length == 0) {
                    mui.toast("The password can't be empty! ");
                    return;
                } else {
                    var url = 'http://zyz1.top/handler/LoginCheck.ashx';
                    mui.ajax(url, {
                        //dataTo send data to the background, it is a JSON object.
                        data: {
                            "cname": cname,
                            "pwd": pwd
                        },
                        //dataType: 'json',
                        /* If the type of response content returned by the background is'application/json', you do not need to specify dataType as JSON.* mime that does not specify the response of the system to the backgroundType gets the corresponding data format, if this time is set to'json'reverse.* and there will be a mistake.* if the backend returns in the responseWhen the type of capacity is'text/plain', when dataType is specified as'json', MUI* automatically converts the JSON string returned in JSON format to JS.On object.*/
                        type: 'post',//The mode of request, the general situation get and post can
                        timeout: 10000,//10seconds until timeout
                        //successIndicates that the request is successful, and the response status code returned is 200.
                        success: function(data) {
                            if(data != 'undefined' && data != null && data != '') {
                                /*data{success:true, child:{cid:'1', cname:'mike', rname:'Zhang three'* or: {sucCess:false, child:null}*/
                                
                                if(data.success == true) 
                                {
                                    mui.toast('Log in successfully! ')
                                    //When 5+ API is used, it must be placed in the plusReady event
                                    mui.plusReady(function() {
                                        mui.openWindow({
                                            url: 'index.html',
                                            id: 'index',
                                            extras: {
                                                cid: data.child.cid,
                                                cname: data.child.cname,
                                                rname: data.child.rname
                                            }
                                        });
                                    });
                                } else {
                                    mui.toast("The username or password is wrong! Please log in again! ");
                                }
                            }
                        },
                        /*
                        *xhr:xhrInstance object*type: the wrong description can be taken as follows: "timeout", "error", "abort", "parsererror" and "null".*errorThrown: capable exception objects*/
                        error: function(xhr, type, errorThrown) {
                            mui.toast("Error inside of the server! ");
                            console.log('error:' + type);
                        }
                    })
                    /*mui.get(url,callback(data))Or mui.post (URL, callback (data)) is a simplified version of Ajax* if you want to set timeouts or handle exceptions, you must use mui.ajax ().              */
                }
            });
        </script>

 

Leave a Reply

Your email address will not be published. Required fields are marked *