g***@163.com
g***@163.com
  • 发布:2017-03-16 21:01
  • 更新:2017-03-16 21:01
  • 阅读:2357

新手请教关于mui ajax timeout问题,谢谢!!!

分类:MUI

实现一个登陆功能

mui.plusReady(function () {  
            document.getElementById('register').addEventListener('tap',function(){  
                mui.openWindow('register.html','register',{})  
            });  
            document.getElementById('login').addEventListener('tap',function(){  
                var wd = plus.nativeUI.showWaiting();  
                var username = document.getElementById("username").value;  
                var password = document.getElementById("password").value;  
                var logininfo = {  
                    username: username,   
                    password: password   
                }  
                mui.ajax("http://192.168.43.190:8080/BookStore/login.jsp",{  
                    data:logininfo,  
                    dataType:'text',  
                    type : 'post',  
                    timeout:10000,  
                    contentType:"application/x-www-form-urlencoded;charset=utf-8",  
                     beforeSend: function() {   
                        console.log('beforesend!' + JSON.stringify(logininfo))  
                        plus.nativeUI.showWaiting();   
                    },  
                    success:function(data){  
                         console.log(JSON.stringify(data))   
                    },  
                    error:function(xhr,type,errorThrown){                     
                    console.log(type);  
                     if(type == 'timeout') {  
                            mui.toast("请求超时:请检查网络")  
                        } else {  
                            mui.toast('请求失败:' + type + '\n err:' + errorThrown);  
                        }  
                    },  
                    complete: function() {  
                        console.log('userLogin:关闭转圈')  
                        plus.nativeUI.closeWaiting();   
                    }  
                }     
                )  

            })    
        })

后台代码是:

 <% Login l = new Login();  
    String data = request.getParameter("data");   
    JSONObject jsonObject = JSONObject.fromObject(data);  
    String username = jsonObject.getString("username");  
    String password = jsonObject.getString("password");  
    String result = l.login(username, password);  
    response.setContentType("text/plain");  
    response.setCharacterEncoding("UTF-8");  
    try{  
        response.getWriter().print(result);  
        response.getWriter().flush();  
        response.getWriter().close();  
    }catch(IOException e){  
        e.printStackTrace();  
    }  
    %>

其中login方法是操作数据库判断登陆是否成功的方法,返回一个String。

控制台输出:

beforesend!{"username":"ruida","password":"4520157"} at html/login.html:76
timeout at html/login.html:84
userLogin:关闭转圈 at html/login.html:92

请问到底是什么原因导致timeout?谢谢

2017-03-16 21:01 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复