最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论