Reputation: 23989
I'm using the following for inline editing.
I want ajax to fire when enter key pressed or user clicks away (blur)
When enter key is pressed all is ok but AJAX not firing on blur?
// inline editing
$(document).on('blur keypress', 'span[contenteditable=true]', function (e) {
if (e.type == 'blur' || e.keyCode == '13') {
$.ajax({
type:'POST',
url:'/ajax/actions/editGenre.php',
data:{
content: $(this).text(),
id: $(this).attr('rowId')
},
success:function(msg){
$('span[contenteditable=true]').removeClass('inlineEdit').addClass('editAble');
}
});
e.preventDefault();
}
});
Upvotes: 0
Views: 1011
Reputation: 7668
Fixed: JSFiddleWiddleBiddleBoDiddle (commented out your AJAX for the fiddle and used an alert to demonstrate)
$(document).on('focusout keypress', 'span.inlineEdit', function (e) {
e.preventDefault();
if (e.type == 'focusout' || e.keyCode == '13') {
$.ajax({
type: 'POST',
url: '/ajax/actions/editGenre.php',
data: {
content: $(this).text(),
id: $(this).attr('rowId')
},
success: function (msg) {
$('span.inlineEdit').removeClass('inlineEdit').addClass('editAble');
}
});
}
});
Upvotes: 2
Reputation: 5432
Blur event does not fire for span tags. Use something else which is meant to receive focus.
Upvotes: 0