日期:2014-05-16  浏览次数:20461 次

JSON Ajax异步请求实现select联动

?

?

$('#selDivision').change(function(){
	    	 $('#nhiPrice').val('');
	    	 clearGoaPrice();
	    	 clearGoaPriceCss();
	         $('#selProdName option').remove();
	         $('#selProdName').append("<option value='-1'>"+'<s:text name="pub.select.tag.please.select"/>'+"</option>"); 
	         $.ajax({
	              type: "POST",   
	              url: "<%=appPath%>/findProdNameByDivision.do",  
	              dataType: "json", 
	              data: {buCode: $('#selDivision').val()}   
	            }).done(function(msg) {
	            	$.each(msg, function(index, obj){
	            		 $('#selProdName').append('<option value="'+obj+'">'+obj+'</option>'); 
	            	 });
	             });   
	     }); 

?

?

function findSysGoaByDivAndProd(msdProdName){
		  $.ajax({
              type: "POST",   
              url: "<%=appPath%>/goaNHIMt_findSysGoaByDivAndProd.do",
              dataType: "json",
              data: {msdProdName: msdProdName,buCode:$('#selDivision').val()}
            }).done(function(data){
                var isNoGoa = true;
            	 $.each(data, function(index, obj){
           		    if(obj.custMsdEntity == '' || obj.custMsdEntity==null){
           		    	$('#goaPrice_'+obj.roleCode).val(toFixed(obj.goaPrice,4));
               		 	$('#id_'+obj.roleCode).val(obj.id);
           		    }else{
           		    	$('#goaPrice_'+obj.custMsdEntity+'_'+obj.roleCode).val(toFixed(obj.goaPrice,4));
               		 	$('#id_'+obj.custMsdEntity+'_'+obj.roleCode).val(obj.id);
           		    }
           		 isNoGoa = false;
           		 });
           		 if(isNoGoa){
           			clearGoaPrice();
           		 }
          	});
	  }

?

?

public void findProdNameByDivision()throws Exception{
		prodList = sysConfigureService.findProdNameByDivision(buCode);
		JSONArray jsonList = JSONArray.fromObject(prodList); 
		PrintWriter out = null;
        HttpServletResponse response = getResponse();
        response.setContentType("text/plain");   
        response.setCharacterEncoding("utf-8");   
        out = response.getWriter();
        out.print(jsonList);
	}

?

?