下面的代码需要从原型迁移到jQuery我写了相当于这段代码,但对如何在jQuery中处理 {success:'added_udf_filters'} 有疑问
new Ajax.Updater({success: 'added_udf_filters'}, '/reports/add_udf_selection_row', {
parameters: {udf_key: filter_key},
method: 'get',
insertion: 'bottom',
evalScripts: true,
onCreate: function() {
$('udfFiltersWorking').show();
},
onComplete: function() {
$('udfFiltersWorking').hide();
},
onSuccess: function(response) {
sel_obj.select('[value=' + filter_key + ']')[0].remove();
if ($('select_udf_filter').select('option').length <= 1)
$('filter_select').up('table').hide();
},
onFailure: function(response) {
alert("Error: " + response.statusText);
}
});
}
});
我在jQuery中编写的等效代码是
jQuery.ajax({
url: '/reports/add_udf_selection_row',
dataType: 'text',
success: function(data) {
jQuery("#added_udf_filters").html(data);
}
})
.done(function(data) {
sel_obj.select('[value=' + filter_key + ']')[0].remove();
if (jQuery('#select_udf_filter').select('option').length <= 1)
jQuery('#filter_select').closest('table').hide();
})
.always(function() { jQuery('#udfFiltersWorking').hide(); })
.fail(function(jqXHR, textStatus, ex) {
"use strict";
alert('Error: ' + textStatus + ' : ' + ex);
});