mui框架Ajax实现前后台交互注意事项:
url地址不能使用127.0.0.1或localhost作为地址,应使用本地其他IP地址。
其他IP地址方法:win+r,打开cmd输入 IPCONFIG,就可以看到自己的本地IP。
代码如下:
<script type="text/javascript" charset="utf-8">
mui.init();
//plusReady,用来定义加载dom后的操作
mui.plusReady(function() {
var userform = document.getElementById("userform");
var username = document.getElementById("uname");
var txt_password = document.getElementById("pwd");
//发起 ajax请求
userform.addEventListener("submit", function(e){
mui.ajax('http://这里写本地查询到的本地IP:8080(这里是tomcat端口号)/xxx/for',{
data:{
name:username.value,
addr:txt_password.value
},
dataType:'json',//服务器返回json格式数据
type:'GET',//HTTP请求类型
timeout:10000,//超时时间设置为10秒;
success:function(data){
}
});
})
})
</script><