javascript - how to pass the value from Jquery to jsp? - Stack Overflow

My jQuery code:function check_availability(){ get the username alert("hai");var result

My jQuery code:

function check_availability(){   

         //get the username   
         alert("hai");
         var result ="";
         var CompanyCode = $('#CompanyCode').val();   
     alert("Jquery " +CompanyCode);
     //use ajax to run the check   
         $.post("checkUserName.jsp", { CompanyCode: CompanyCode },   
             function(result){   
                 //if the result is 1   
                 alert("result"+result);
                 if(result == 1){   
                     //show that the username is available   
                     $('#username_availability_result').html(CompanyCode + ' is Available');   
                 }else{   
                     //show that the username is NOT available   
                     $('#username_availability_result').html(CompanyCode + ' is not Available');   
                 }   
         });   

}

checkUserName.jsp:

String panyCode = request.getParameter("CompanyCode");
out.println("panyCode"+panyCode);

rs = dbAccess.executeQuery("select panycode from yosemitepany where panycode = '"+panyCode+"'");

How to get the values from jQuery? I need to get the answer in the JSP page for checking ,whether the record is present or not in the table. I am not getting the value from the request.getParamater() method. Is this any other way to check that ?

My jQuery code:

function check_availability(){   

         //get the username   
         alert("hai");
         var result ="";
         var CompanyCode = $('#CompanyCode').val();   
     alert("Jquery " +CompanyCode);
     //use ajax to run the check   
         $.post("checkUserName.jsp", { CompanyCode: CompanyCode },   
             function(result){   
                 //if the result is 1   
                 alert("result"+result);
                 if(result == 1){   
                     //show that the username is available   
                     $('#username_availability_result').html(CompanyCode + ' is Available');   
                 }else{   
                     //show that the username is NOT available   
                     $('#username_availability_result').html(CompanyCode + ' is not Available');   
                 }   
         });   

}

checkUserName.jsp:

String panyCode = request.getParameter("CompanyCode");
out.println("panyCode"+panyCode);

rs = dbAccess.executeQuery("select panycode from yosemitepany where panycode = '"+panyCode+"'");

How to get the values from jQuery? I need to get the answer in the JSP page for checking ,whether the record is present or not in the table. I am not getting the value from the request.getParamater() method. Is this any other way to check that ?

Share Improve this question edited Nov 27, 2010 at 7:57 Adalarasan Sachithanantham asked Nov 27, 2010 at 7:01 Adalarasan SachithananthamAdalarasan Sachithanantham 1,3174 gold badges14 silver badges28 bronze badges 11
  • @adal arasan you can not get from request.getParameter() , its not a server call right. – kobe Commented Nov 27, 2010 at 7:24
  • ok .how to get the values from it.After i get the values am checking with the database whether it's present or not.so am using the jsp page for process the data.Is it correct or not ? – Adalarasan Sachithanantham Commented Nov 27, 2010 at 7:34
  • @adal sorry , is that how you get querystring in jsp , i am from background , we use request.querystring/// – kobe Commented Nov 27, 2010 at 7:38
  • @adal,finally what happened is it working , you can check in net panel of firebug – kobe Commented Nov 27, 2010 at 7:51
  • gov,i need ur help..it's still not working...am in the deadline...can u help me.. – Adalarasan Sachithanantham Commented Nov 27, 2010 at 7:58
 |  Show 6 more ments

3 Answers 3

Reset to default 2

Instead of

     $.post("checkUserName.jsp", { CompanyCode: CompanyCode },   

Try

     $.post("checkUserName.jsp", { Code: CompanyCode },   

Perhaps it's an issue with naming the keys the same as that var...

Your code is absolutely valid. Only thing as said above the variable naming may the issue. You can try the other option from jquery api,

$.post("checkUserName.jsp", $('#CompanyCode').serialize(),..

This should take care of your issue. Because query string values should be quoted ('') properly. This serialize method would take care of that.

It seems that CompanyCode is the id attribute.So just create an attribute name="something" then use request.getParameter("something").I hope it will work

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745580521a4634227.html

相关推荐

  • javascript - how to pass the value from Jquery to jsp? - Stack Overflow

    My jQuery code:function check_availability(){ get the username alert("hai");var result

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信