我有一个ajax请求如下:
jQuery.ajax({
type: 'GET',
url: '/logical_interface/delete',
context: this, // had to add this to get the line in the success function to work, never used it before nor do I understand why it works
data: 'id=' + id,
beforeSend: function() {
// jQuery(this).parent().html('processing...');
// if this line is uncommented then the DOM will be updated correctly
// but the snippet in the success function won't fire but the delete
// is still executed on the server side
// the page is then stuck with the 'processing' text
},
success: function(data) {
jQuery(this).closest('tr').stop().animate({ backgroundColor: '#ffc6be' }, 'fast').hide('slow');
}
});
更新
服务器端代码就是下面的 Rails 方法:
def delete
@logical_interface = LogicalInterface.find(params[:id])
@logical_interface.destroy
render :text => '1' // which is what I get in console.log
end