2014-01-05 3 views
0

jquery 양식을 서블릿에 사용하고 있습니다. xyz 값을 서블릿에 보냅니다. xyz에 알맞은 값을 표시하지만 콜백 함수의 데이터 경고는 null으로 표시됩니다. 여기 내 스크립트 여기jquery 양식 서블릿 제출

<script> 
    $(document).ready(function(){ 

      $("#country_id").change(function() { 
      var xyz = $("option:selected").val(); 
       alert(xyz) 
      // var url ="../Retrive_country?stateadd_1=none&countryREF="+xyz; 
       $.get("../Retrive_country?stateadd_1=none", 
       {countryref : xyz } ,function(data,status){ 
      alert("Data: " + data + "\nStatus: " + status); 
      }); 

      //$(location).attr('href',url); 

     }); 
     }); 
     </script> 

이다 내가 잘못

String countryref= request.getParameter("countryREF"); 
String sql1 = "SELECT * FROM state WHERE country_ref="+countryref+" "; 
PreparedStatement pst1 = db.getConnection().prepareStatement(sql1); 
ResultSet j = pst1.executeQuery(); 
while (j.next()) { 
         String state_id = j.getString(1); 
         state = j.getString(2); 
         country_ref = j.getString(3); 
         location.setState(state); 
         location.setState_id(state_id); 
         location.setcountry_ref(country_ref); 
        } 
pw.println(countryref); 

를하고있는 중이 야 .. 내 JSP 여기

<html> 
<body> 
<div class="span2 clear"> 
<select name="country_id" id="country_id"> 
<option>-select-</option> 

<option value="1" id="blabbb">1</option> 
<option value="2" id="blabbb">2</option> 
<option value="3" id="blabbb">3</option> 
</select></div> 
</body> 
</html> 

내 서블릿은 무엇?

$(document).ready(function() { 
    $("#country_id").change(function() { 
     var xyz = $("option:selected").val(); 
     $.get("../Retrive_country?stateadd_1=none", { 
      countryref: xyz 
     }) 
      .done(function (data) { 
      alert("Data Loaded: " + data); 
     }); 
    }); 
}); 

OR :

답변

1

서버 측 코드가 기대를 countryREF (대소 문자 구분) 요청 데이터에 아마 그래서 전달 된 데이터를 { countryREF: xyz }으로 변경해야합니다.

<script> 
    $(document).ready(function(){ 
     $("#country_id").change(function() { 
     //var xyz = $("option:selected").val(); 
     var xyz = $(this).val(); 

     alert(xyz); 

     $.get("../Retrive_country?stateadd_1=none", { countryREF: xyz }, function(data,status){ 
      alert("Data: " + data + "\nStatus: " + status); 
     }); 

     }); 
    }); 
</script> 
+0

thanx jjenzz thi works nw. – 3bu1

0

From the jQuery documentation, 당신은 $.get의 형식을 시도 할 수 있습니다

$(document).ready(function() { 
    $("#country_id").change(function() { 
     var xyz = $("option:selected").val(); 
     $.get("../Retrive_country?stateadd_1=none&countryref=" + xyz, function (data) { 
      alert("Data Loaded: " + data); 

     }); 
    }); 
});