spring mvc框架下 後臺往前臺傳送json數據

1.後臺代碼:

public String aas(HttpServletRequest request,HttpServletResponse response) 
JSONObject jo = new JSONObject();
		if(條件){
                          jo.put("result","yes");
                         }

                  else{
                          jo.put("result","yes");
                          }
PrintWriter pw = null;
		String data=jo.toString();
		try {  
            pw = response.getWriter();  
            pw.write(data);  
        } catch (IOException e) {  
            e.printStackTrace();  
        }finally{
	        pw.close();
        }
		
		 return null;
		 }

2.前臺代碼:

$.ajax({
        type: "POST",
        url: "*****",
        
        data:****,
        success: function(data) {
        	 var obj=eval("("+data+")");
              if(obj.result="yes")
                      {     }
              else{
                          }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章