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 ?
- @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
3 Answers
Reset to default 2Instead 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