ajax前後臺json數據交互

前臺:

		$.ajax({
				url:'LoginAction_toLogin.jspx',
				type: 'post', dataType:'json', cache: false, async:false,
				data: {"username":username, "password":password},
				success: function(result){
					if(result["flag"] == '0'){
						window.location.href = "MenuAction_toInfo.jspx";
					}else if(result["flag"] == '1'){
						var txt="用戶名或密碼錯誤,請重新登錄";
						window.wxc.xcConfirm(txt);
					}
				}
			});

注意的是jesult是json格式數據,如果result[“flag”]的值是true,if(true){}是不成立的

後臺:

public void toLogin(){
		JSONObject json = new JSONObject();
 		json.put("flag", "0");
 		this.renderText(json.toString());     //getHttpServletResponse().getWriter().write(text);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章