Hbuilder app开发,使用mui.ajax和服务器交互

.mui.ajax的写法:

var inpt_mobile = document.getElementById("inpt_mobile");
var inpt_pwd = document.getElementById("inpt_pwd");
url:"http://***.***.***.***:8080/Smart_Toilet2/a",
        type:‘post‘,
        data:{
            username:inpt_mobile.value,
            password1:inpt_pwd.value,
        },
        dataType:‘text‘,
        timeout:10000,
        success:function(res){
      
        },
        //异常处理
        error:function(e){
            console.log(e);
        }
})

servlet的写法:

String a = request.getParameter("username");
        System.out.print(a);

 

获取后台数据mui.ajax的写法:

function login() {
    var uname=document.getElementById("username").value.trim();
    var pwd=document.getElementById("password").value.trim();
    mui.toast("0 "+uname+" "+pwd);
    
    mui.ajax(
        ‘http://192.168.63.2:8080/ServletTest/servlet/AjaxTest‘,{
        data: {
            uname:uname,
            pwd:pwd
        }, 
        dataType: ‘text‘,
        type: ‘post‘,
        timeout: 10000,
        headers: {
            ‘Content-Type‘: ‘application/x-www-form-urlencoded‘
        }, 
        success: function(data) {
            mui.toast("success "+data);
        },
        error: function(xhr, type, errorThrown) {
            mui.toast("error "+type);
            console.log(xhr,type,errorThrown);
        }
    });
}

 

Hbuilder app开发,使用mui.ajax和服务器交互

上一篇:Android开发:输入框点击后弹出的小键盘把页面向上挤压问题解决


下一篇:苹果拥抱 Rust,正在将 C 代码移植到 Rust