今天搞了好久这个前后端数据交互的过程,有点难受,写点总结吧
1 html文件传输数据(AJAX)
$.ajax({
type:"POST",
dataType:"json",
url:"UserServlet?method=loginAjax",
data:{
"loginacct":loginacct,
"userpasswd":userpasswd
},
//考虑到发送数据过程中网络延迟等情况,加入layer的等待效果,用户体验良好
beforeSend:function(){//加载的操作,发送数据前
//使用插件的效果
loadingIndex=layer.msg("处理中",{icon:16});
},//服务器返回结果后,采取动作
//jsondata--"{"success":"true","result":"{"":"","":""}","message":"info---"}"
success:function(data){
//Json.parse(result.result)
layer.close(loadingIndex);//拿到数据了就应该关闭等待效果
if(data.success){//可以对后台传过来的值进行判断
window.location.href="/DispatcherServlet?method=mainPage";
}else{