在ajax调用之后运行js函数会将传入数据放入元素

时间:2022-01-10 23:56:12

I have an ajax link in my application:

我的应用程序中有一个ajax链接:

<head>
<script type="text/javascript">function GoFurther() { ... }</script>
</head>
...
<%= Ajax.ActionLink("Go", "SomeAction", "SomeController", new AjaxOptions() { UpdateTargetId = "someDiv" }) %>
<div id="someDiv"></div>

I want to execute GoFurther() after ajax request completes AND someDiv is filled with its content so that it can bind some events on some buttons that've come from server. OnCompleted and OnSuccess seem to work after the ajax answer is received but before someDiv is filled. So they do not work for me.

我希望在ajax请求完成后执行GoFurther()并且someDiv会填充其内容,以便它可以绑定来自服务器的某些按钮上的某些事件。 OnCompleted和OnSuccess似乎在收到ajax答案但在someDiv填充之前有效。所以他们不适合我。

To be clear, some div will be filled with some content after ajax call:

为了清楚起见,在ajax调用之后,一些div将填充一些内容:

<someDiv><input type="button" value="Click" class="someButton" /></someDiv>

GoFurther makes some bindings using $(".someButton").click(...); so it must run once someDiv is completely filled. How can I make sure it runs after someDiv is filled?

GoFurther使用$(“。someButton”)进行一些绑定。点击(...);所以它必须在someDiv完全填满后运行。我怎样才能确保它在someDiv填满后运行?

1 个解决方案

#1


OnSuccess is supposed to run after the DOM element has been updated [according to the source code for the Mvc Ajax Helpers - see OnComplete method]. Is there a particular problem that is occurring when you use OnSuccess?

OnSuccess应该在DOM元素更新后运行[根据Mvc Ajax Helpers的源代码 - 参见OnComplete方法]。使用OnSuccess时是否存在特定问题?

#1


OnSuccess is supposed to run after the DOM element has been updated [according to the source code for the Mvc Ajax Helpers - see OnComplete method]. Is there a particular problem that is occurring when you use OnSuccess?

OnSuccess应该在DOM元素更新后运行[根据Mvc Ajax Helpers的源代码 - 参见OnComplete方法]。使用OnSuccess时是否存在特定问题?