views:

41

answers:

2

hi in my jsp page i am a having a jquery area which pass the values to a servlet which returns an output of dropdownlist . then the jsp file do some updation so certain values which are in the dropdownlist should not be there while repopulating. but it is not happening. my jquery code is

 $("#cbocode").change(function(){
   var cdid=$("#cbocode option:selected");
   $.get("trnDC?caseNo=20&cdid="+cdid.text(),function(data){
       $("#divinstrument").html(data);
   })

and the servlet code is

 case 20:{ //jquery call
                    String cdid=(String) request.getParameter("cdid");
                    Statement st = con.createStatement();
                    ResultSet rs = st.executeQuery("select instrumentid from mstinstrument where codeid='" + cdid + "' and rec_Status='A' and statusid='U' and Agentid='METLAB'");
        if (!rs.wasNull()){
                    //List data=new ArrayList();
                    String v="<select id=cboinstr>";
                   while (rs.next())
                   {
                    //   data.add(rs.getString("vend_code"));
                     v += "<option>" + rs.getString("instrumentid").toString() + "</option>";
                   }
                    v+="</select>";
                    response.setContentType("text/html");
                    PrintWriter out = response.getWriter();
                    out.print(v);
                    }
                    else{
                        response.setContentType("text/html");
                    PrintWriter out = response.getWriter();
                    out.print("no data found");
                    }

where i am missing???

+2  A: 

get requests are cached by the browser. Use cache: false with the ajax method.

Instead of:

$.get("trnDC?caseNo=20&cdid="+cdid.text(),function(data){
       $("#divinstrument").html(data);
   })

Use:

$.ajax({url: "trnDC?caseNo=20&cdid="+cdid.text(),
       cache: false,
       success: function(data){
                    $("#divinstrument").html(data);
                }
       });
kgiannakakis
sorry for being such ignorant could u point out area in which i have to use the statement
sansknwoledge
+1  A: 

By default get requests are cached. You can use what @kgiannakakis suggests and set cache:false. I'm not 100% but I think that Internet Explorer might have an issue with that method?

To do that you would need to change from using $.get to using $.ajax, like:

$.ajax({
   type: 'GET'      
   url: "trnDC?caseNo=20&cdid="+cdid.text(),
   success: function(data){
               $("#divinstrument").html(data);
   },
   cache: false
});

There are 2 other ways that I can think of to get round your problem:

Change from Get to Post.

$.post("trnDC?caseNo=20&cdid="+cdid.text(),function(data){
       $("#divinstrument").html(data);
   })

Add in a 'false' parameter that will always be different, like javascripts Date.getDate()

Fermin
thanks boss it is now working
sansknwoledge