ReferenceError: function is not defined - JavaScript

前端 未结 1 875
南旧
南旧 2020-12-18 21:43

I\'m trying to create a Javascript chat, with Python on the backend. This is the code I\'m using ...



<         


        
相关标签:
1条回答
  • 2020-12-18 22:40

    This happens when you define the functions in the head part and call them, when the document is not yet initialized. Move the script part, where the initialization happens and try it out.

    Since you are using jQuery, it would also be better, if you can initialize the variables and enclose the whole script under a function and call the function inside document's ready state, it would probably work.

    $(document).ready(function(){
       var chat_id = 1;
       init_chat({{ chat_id }}, "chat");
       // Something wrong here. Is it really chat_id inside {{ }}?
    });
    
    0 讨论(0)
提交回复
热议问题