We are new to JQuery but have quite a bit of programming experience.
我们是JQuery的新手,但有很多编程经验。
We have a web application that performs load-on-demand AJAX calls. Whenever a user scrolls up or down, it makes small requests to the server to request more data. The AJAX call is made whenever an empty div (each having a unique ID) appears on-screen, then the corresponding data is loaded, so on and so forth.
我们有一个Web应用程序,可以执行按需加载的AJAX调用。每当用户向上或向下滚动时,它向服务器发出少量请求以请求更多数据。只要屏幕上出现空div(每个都有一个唯一的ID),然后加载相应的数据,依此类推,就会进行AJAX调用。
We realized that none of the JQuery was working because the parent document was loaded before any real data was inserted using AJAX. So the $(document).ready(function() was already called before any AJAX data was inserted into the parent document. We overcame this by creating a JQuery function that called each of the functions and inserted it into each AJAX-called HTML snippet:
我们意识到JQuery没有工作,因为在使用AJAX插入任何实际数据之前加载了父文档。因此在将任何AJAX数据插入父文档之前已经调用了$(document).ready(function()。我们通过创建一个调用每个函数的JQuery函数并将其插入到每个AJAX调用的HTML片段中来克服这个问题。 :
AJAX-called HTML:
AJAX称为HTML:
$(document).ready(function(){ callBackFx(); });
JQuery Function:
JQuery函数:
this.callBackFx = function(){ vectorToggle(); //list of fxs()... atooltip(); };
Which worked, except each time a new div is loaded via AJAX, it calls the JQuery functions each time a new div is loaded, which obviously causes problems. We have tried to pass the id of the parent div to the overall callBackFx function, but haven't gotten it to work.
哪个工作,除了每次通过AJAX加载一个新的div,它每次加载一个新div时调用JQuery函数,这显然会导致问题。我们试图将父div的id传递给整个callBackFx函数,但还没有让它工作。
Any ideas are much appreciated.
任何想法都非常感谢。
2 个解决方案
#1
0
Try to bind the ajax call to the 'scroll' event handler, each time the scroll reaches a new div, here you can find an example:
尝试将ajax调用绑定到'scroll'事件处理程序,每次滚动到达一个新div时,在这里你可以找到一个例子:
http://www.webresourcesdepot.com/load-content-while-scrolling-with-jquery/
http://www.webresourcesdepot.com/load-content-while-scrolling-with-jquery/
#2
0
We figured out that we need to pass the div id as a parameter to each of the functions rather than to a single, all-inclusive function.
我们发现我们需要将div id作为参数传递给每个函数,而不是传递给单个全包函数。
#1
0
Try to bind the ajax call to the 'scroll' event handler, each time the scroll reaches a new div, here you can find an example:
尝试将ajax调用绑定到'scroll'事件处理程序,每次滚动到达一个新div时,在这里你可以找到一个例子:
http://www.webresourcesdepot.com/load-content-while-scrolling-with-jquery/
http://www.webresourcesdepot.com/load-content-while-scrolling-with-jquery/
#2
0
We figured out that we need to pass the div id as a parameter to each of the functions rather than to a single, all-inclusive function.
我们发现我们需要将div id作为参数传递给每个函数,而不是传递给单个全包函数。