$(this).find(':submit').attr('disabled',true);
$.ajax(
{
url:'/enviarSugerenciaMessageBoard',
cache: false,
type: 'POST',
data: $(this).serialize(),
success: function(success)
{
if(success=='Envio correcto')
{
console.log('Envio correcto');
$(this).find(':submit').attr('disabled',false);
}else{
console.log('Error en el envio');
$(this).find(':submit').attr('disabled',false);
}
}
});
this ajax query works fine the problem is when i get 'Envio correcto' from server, in console i get Envio correcto but the attr disabled false dont work...
i try to make other functions on success like append or prepend but didnt work
even in async:false
Because this keyword is not belong that element anymore in success function. You should backup this variable to another variable, than you can use it.
Like this,
$(this).find(':submit').attr('disabled',true);
var self = this;
$.ajax(
{
url:'/enviarSugerenciaMessageBoard',
cache: false,
type: 'POST',
data: $(this).serialize(),
success: function(success)
{
if(success=='Envio correcto')
{
console.log('Envio correcto');
$(self).find(':submit').attr('disabled',false);
}else{
console.log('Error en el envio');
$(self).find(':submit').attr('disabled',false);
}
}
});
Inside the success callback, this is not what it was from where you called .ajax(). To control the value of this inside the callback, you can use the context option in .ajax()
In your case, all you need to do is:
$.ajax({
context: this, // what you wnat `this` to be inside success
url:'/enviarSugerenciaMessageBoard',
...
success: function(success) {
// 'this' is what you passed in via context
});
Docs: http://api.jquery.com/jQuery.ajax/ - Scroll down to see the context option