<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("用戶名不能為空!") return; } else if(pwd.trim().length == 0) { mui.toast("密碼不能為空!"); return; } else { var url = 'http://zyz1.top/handler/LoginCheck.ashx'; mui.ajax(url, { //data為要發送到后台的數據,是一個json對象 data: { "cname": cname, "pwd": pwd }, //dataType: 'json', /* 如果后台返回的響應內容的類型是'application/json'時,可不用指定dataType為json, * 不指定系統會根據后台響應的mime類型來得到相應的數據格式,如果此時設置為'json'反 * 而會出錯。 * 如果后台返回的響應內容的類型是'text/plain'時,此時dataType指定為'json'時,mui * 會自動將返回的符合json格式的json字符串轉換為json對象。 */ type: 'post',//請求方式,一般情況get和post都可以 timeout: 10000,//10秒超時 //success表示請求成功,返回的響應狀態碼為200時 success: function(data) { if(data != 'undefined' && data != null && data != '') { /*data形如:{success:true,child:{cid:'1',cname:'mike',rname:'張三'}} * 或:{success:false,child:null} */ if(data.success == true) { mui.toast('登錄成功!') //使用5+ api時,必須放在plusReady事件中 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("用戶名或密碼不對!請重新登錄!"); } } }, /* *xhr:xhr實例對象 *type:錯誤描述,可取值:"timeout", "error", "abort", "parsererror"、"null" *errorThrown:可捕獲的異常對象 */ error: function(xhr, type, errorThrown) { mui.toast("服務器內部錯誤!"); console.log('error:' + type); } }) /*mui.get(url,callback(data))或mui.post(url,callback(data))是ajax的簡化版 * 如果要設置超時,或處理異常時,必須用mui.ajax() */ } }); </script>