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.