简体   繁体   English

AJAX回发后JavaScript不起作用(jQuery Backstretch和Telerik RadAjaxManager)

[英]JavaScript not working after AJAX postback (jQuery Backstretch and Telerik RadAjaxManager)

I am using jQuery Backstretch ( http://srobbin.com/jquery-plugins/backstretch/ ), but after an AJAX update via an RadAjaxManager AjaxRequest (kicked off clientside), it dies. 我正在使用jQuery Backstretch( http://srobbin.com/jquery-plugins/backstretch/ ),但是在通过RadAjaxManager AjaxRequest(从客户端启动)进行AJAX更新后,它死了。

I have tried re-initializing after the AJAX, but no dice. 我尝试在AJAX之后重新初始化,但是没有骰子。 Other jQuery plugins are still working though (ie Countdown for jQuery - http://keith-wood.name/countdown.html ). 不过,其他jQuery插件仍在工作(例如jQuery的倒数-http: //keith-wood.name/countdown.html )。

JS Page Load: JS页面加载:

$(document).ready(function () {
  $('#timer').countdown({
    until: new Date(2014, 5 - 1, 1)
  });

  $.backstretch([
    'images/bg1.jpg',
    'images/bg2.jpg',
    'images/bg3.jpg'
     ], {
     fade: 750,
     duration: 4000
  });
});

Javascript called for a button click: 要求按钮单击的Javascript:

$find("<%= RadAjaxManager1.ClientID %>").ajaxRequest();

VB: VB:

Protected Sub RadAjaxManager1_AjaxRequest(sender As Object, e As AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest
    'Do something
End Sub

After the AjaxRequest has run, the Countdown is still running, but the Backstretch images have disappeared! 在AjaxRequest运行之后,倒计时仍在运行,但是Backstretch图像消失了!

Help? 救命?

You may wish to rebind to the IDs. 您可能希望重新绑定到ID。

Otherwise, for the purpose of debugging, please try to re-run the js script after the ajax call. 否则,出于调试目的,请尝试在ajax调用后重新运行js脚本。

 $(document).ready(function(){
       //your ajax call
       $.getScript("jquery.min.js");
 });

Wrap your function into a self invoke function as this: 将您的函数包装为一个自调用函数,如下所示:

(function($){
  $(document).ready(function () {
 ...
  });
});})($telerik.$)

this will load the jquery from the telerik libraries. 这将从telerik库加载jquery。

As for the reason it has something to do with the way Telerik handles ajax and it does not load jquery from your references libraries. 由于这个原因,它与Telerik处理ajax的方式有关,并且不会从您的引用库中加载jquery。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM