jquery ajax削除操作の追加


   web     ,                  ,                 ,          ,                

         ,           html+json+jquery+ajax    ,      web     , :ASP、Jsp、PHP、Dijango、Ruby on Rails   

            ,            、  、    
  • 追加操作
  • //------------------------------------------------------------------------------------------------
    function user_add(){//    
    //	data :{ip:''+ip+'',type:''+type+'',owner:''+owner+''}
    	var arr=$('form').serialize();
    	$.ajax({url : 'user_add.do',type : 'post',data : arr,dataType : 'text',timeout : 10000,error : function() {
    		alert('      !');
    	},
    	success : function(data) {
    		if(data==1){
    			alert('    !');				
    		}else{
    			alert('    !');
    		}
    					
    	}
    });
    
    }
    
    //------------------------------------------------------------------------------------------------

     
       2.アクションの削除
     
    //-----------------------------------------------------------------------------------------
    function user_del(obj){//    
    //	data :{ip:''+ip+'',type:''+type+'',owner:''+owner+''}
    //	var arr=$('form').serialize();
    	$.ajax({url : 'user_del.do',type : 'post',data : {name:''+obj.alt+''},dataType : 'text',timeout : 10000,error : function() {
    		alert('del data failure!');
    	},
    	success : function(data) {
    		$('#msg').text('').show();
    		var reg=confirm("           ?")
    		if(reg==true){
    			if(data==1){
    				$('#msg').text('【    】:     【'+obj.alt+'】       !').fadeOut(5000);
    				get_json();	
    			}else{
    				$('#msg').text('【    】:     【'+obj.alt+'】       !').fadeOut(5000);
    			}			
    		}
    	}
    });
    }
    //------------------------------------------------------------------------------------------

      
     
    	// ------------------------------------------------------------------------------------------------
    	@RequestMapping(value = "get.do", method = RequestMethod.POST)
    	public void demo(ModelMap model,HttpServletRequest req,HttpServletResponse rsp) throws Exception {
    		String name=req.getParameter("query");
    		UserDao ud=new UserDao();
    		ArrayList<User> list=ud.getAll();
    		Gson gson=new Gson();
    		String listToJson = gson.toJson(list);
    		
    		//            JSON        
    		rsp.setContentType("text/html;charset=utf-8");  
    		PrintWriter out = rsp.getWriter();  
    		out.println(listToJson);  
    //		System.out.println(listToJson);			
    	}
    	// ------------------------------------------------------------------------------------------------