views:

636

answers:

1

Hi,

I'm using Jquery validate plugin.I need to validate two fields. I have some problems with the following code.I'm checking whether the given element valid and if it is valid I make an ajax call to check for few values and hide or show elements based on that. The problem is when the blur event happens, the validation is done. But the ajax request is not happening. How can i solve this problem. Thanks in advance.

$("#code").bind('blur',function(event) {

var isValid = $("#code").valid();
if(isValid)
{
$.ajax({
  type: "GET",
  url: "/ajaxValidateWithCode",
  dataType: "json",
  data: ({code : $("#code").attr('value')}),
  success: function(msg){
     //alert( "Data Saved: " + msg );

     if(msg)
     {
        $("p#code").show();
     }
     else
     {
        $("p#code").hide();
     }
   }
});

}
else
{
    $("p#code").hide();
}
});
A: 

What do you mean by "the ajax request is not happening"?

Does it send the request (check firebug), any script errors?

You can try changing the data property to:

data: { code : $("#code").val() },
redsquare
Hi,I checked firebug console and GET /ajaxValidateWithCode is not happening.no request is send
someisaac
heh, is `isValid` true?
geowa4
yes isValid is true
someisaac