Getting undefined

take a look at the code below:

$('#savestaff').click(function(e)
 { 
    e.preventDefault(); 
    var staffnumber=$('.staff:visible:first').filter(function() { return this.value != "" }).length; 
 

        $.ajax({
          type: "POST",
          url: "stafajax.php",  
          dataType:"json",
          cache:false,
          data:{form:$( "#stafser" ).serialize()},
          success:function(data){
              if(data[0].action=='add')
               {            
               }
              if(data[0]=='remove')
               {             
                 console.log('inside remove block',staffnumber);//here
                  if(staffnumber==1)
                  {
                  }
                  else if(staffnumber==0)
                  {
                    
                  }
               }
          },
          error:function(jqXHR, textStatus, errorThrown){}
          
        });
        
        
 });

take a look at the variable declaration staffnumber…it takes place after e.prevent.default.
And here is my problem:inside the success function of the ajax request-in the remove block(I use console.log to print it’s value)…the variable is undefined…I cannot understand it.

I found the solution after all…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.