我想在渲染ajax响应后执行一段
javascript. javascript函数是在ajax请求期间动态生成的,并且在ajax响应中. ‘完成’和’成功’事件不能完成这项工作.我在Firebug控制台中检查了ajax请求,并且在执行完整回调时没有呈现响应.
Does not work:
function reloadForm() {
jQuery.ajax({
url: "<generate_form_url>",type: "GET",complete: custom_function_with_js_in_response()
});
};
ajaxComplete完成这项工作,但它会对页面上的所有ajax调用执行.我想避免这种情况.有可能的解决方案吗?
$('#link_form').ajaxComplete(function() {
custom_function_with_js_in_response();
});
你也可以使用$.ajax(..).done(do_things_here());
$(document).ready(function() {
$('#obj').click(function() {
$.ajax({
url: "<url>"
}).done(function() {
do_something_here();
});
});
});
还是有另一种方式
$(document).ready(function() {
$('#obj').click(function() {
$.ajax({
url: "<url>",success: function(data){
do_something_with(data);
}
})
});
});
请利用此引擎分享您的问题并尝试解决方案.它非常有效.
http://jsfiddle.net/qTDAv/7/(PS:这包含要尝试的样本)
希望能有所帮助