Ajax回发未调用javascript函数

问题描述:

在页面上加载成功调用的javascript函数,但是当使用ajax进行页面回发时,javascript不再被调用.

On page load the javascript functions called successfully, but when the page postback with the ajax the javascript didn''t called again.

Thanks!

AJAX调用返回时,它不会导致页面加载事件触发,因为发生的一切是在后台检索了一些信息,并且页面的一部分已更新,这不是页面重新加载.

如果您希望在AJAX调用完成后再次调用javascript函数,则需要通过直接调用或使用setTimeout [
When an AJAX call returns it does not cause the page load event to fire as all that is happening is that some information has been retrieved in the background and a part of the page is updated this is not a page reload.

If you want the javascript function to be called again once the AJAX call has completed you need to put a call to the original javascript function in the function that handles the javascript response either through a direct call or use the setTimeout[^] function to delay the call slightly which is a better option.


您需要在调用后显式调用Javascript函数.
为此,如果要从JS函数启动Ajax调用,则需要在从服务器收到响应后再调用函数.

如果您使用的是Updatepanel,则可以将功能注册为启动脚本块,如
You need to call the Javascript function explicitely, after the call.
For that if you are initiating Ajax call from JS function, the you need to call your function after recieving the response from server.
Or
If you are using Updatepanel, the you can register your function as startupscript block as
ScriptManager.RegisterStartupScript(this.Page, typeof(System.Web.UI.Page), "StartupScript", "<script type=''text/javascript'' language=''javascript''>javascript:yourfunction()</script>", false);