0

I have a rather simple JS code, that based on user selected category(that is loaded trough JS function that again calls ajax) calls other JS functions, that also calls JS function and Ajax and so on. What I wanted is that trough usage of cookies, user selected categories are saved on page refresh.

The problem Im facing is, that on refresh, no mather how i call those functions with values i got from cookies (basically the same as user clicks, but in rapid succesion), they only load the ajax, but dont hide the elements that is done before ajax call (maybe because previous functions hasnt updated DOM yet, so there`s nothing to hide).

Basically I need a way to wait for DOM load, and other JS functons/ajax calls and only then call the function.

  • Have you tried `$( document ).ready() { ... }`? – Asons Dec 30 '16 at 15:57
  • 1
    Please refer to this link http://stackoverflow.com/questions/10933501/whats-the-difference-between-window-loadfunction-and-function/10933933#10933933 – prashant Dec 30 '16 at 15:59
  • @LGSon Yeah, '$( document ).ready() { ... }' won`t wait for JS to complete – Bruno Krūmiņš Dec 30 '16 at 16:01
  • @prashant '$(window).load(function(){});' also dosnt wait for whole JS functions completion, inluding ajax data transfer and its data proper adding to HTML. atlest for me it did not work. – Bruno Krūmiņš Dec 30 '16 at 16:03
  • 1
    if your js function is asynchronous then $(window).load(function(){}) would not wait....so in that case you have to refresh only when the sucess callback is invoked... – prashant Dec 30 '16 at 16:07

0 Answers0