jQuery $(document).ready () fires twice

前端 未结 13 834
忘了有多久
忘了有多久 2020-11-29 03:13

I\'ve been sifting around the web trying to find out whats going on here and I have not been able to get a concrete answer.

I have one $(document).ready

相关标签:
13条回答
  • 2020-11-29 03:49

    You might consider to use

    window.onload
    

    instead of

    $(document).ready
    
    0 讨论(0)
  • 2020-11-29 03:57

    It happened to me also, but I realized that the script had been included twice because of a bad merge.

    0 讨论(0)
  • 2020-11-29 03:59

    try putting this in your functions.js to prevent it from being executed twice :

    var checkit = window.check_var;
    if(checkit === undefined){ //file never entered. the global var was not set.
        window.check_var = 1;
    }
    else {
        //your functions.js content 
    }
    

    however i suggest that you look more into it to see where are you calling the second time.

    0 讨论(0)
  • 2020-11-29 03:59

    I had a similar problem when I was trying to refresh a partial. I called a return ActionResult instead of a return PartialViewResult. The ActionResult caused my ready() to run twice.

    0 讨论(0)
  • 2020-11-29 03:59

    I had this problem with window.load function was executed twice: The reason was because I had reference to the same javascript-file in the main page as well as a .net usercontrol. When I removed the reference in the main page, the load-function was only executed once.

    0 讨论(0)
  • 2020-11-29 04:01

    In my case $(document).ready was firing twice because of bad CSS, check if any part of your CSS has background-image: url('');

    0 讨论(0)
提交回复
热议问题