JavaScript code
function existProduct(obj){
var productname = escape(obj.val());
$.getJSON("../product/searchProductByName.action",datat,function(data){
var falg;
falg = data[0]['existproduct'];
//falg returns no or yes,
return falg;
});
}
function validateform( ){
//alert(existProduct($("#products_name")));
if(validateNotnull($("#products_name"))){
if(existProduct($("#products_name "))){
$("#productform").submit();
}else{
$("#spanproduct").html("Business name already exists");
}
}else{
$("#spanproduct").html("Business name cannot be empty");
}
}
In this existProduct( obj) In this function, I call the getJSON function in jquery to return the search results in the database. I checked this with firebug and there should be no problem. What is outrageous is that during execution, the code executes return falg first, and then executes getJSON. Please give some advice from experts