Help me find a bug. I use Handlebars and jQuery. When the page is opened, everything works, but if you switch to another view and return, I get an error in the browser:

description : undefined fileName : undefined lineNumber : undefined message : "You must pass a string or Handlebars AST to Handlebars.compile. You passed undefined" name : "Error" number : undefined stack : "Error: You must pass a string or Handlebars AST to Handlebars.compile. You passed undefined 

My code is:

 <tbody id="user-list"> <script id="user-records" type="text/x-handlebars-template"> {{#each user}} <tr> <td>{{username}}</td> <td>{{role}}</td> <td>{{firstName}}</td> <td>{{lastName}}</td> <td>{{email}}</td> <td>{{notes}}</td> <td>{{activeState}}</td> <td> <a href="#">[Delete]</a> <a href="#">[Edit]</a> </td> </tr> {{/each}} </script> </tbody> function listUsers() { $.ajax({ method: "GET", url: "/users", success: userSuccess, error: handleAjaxError }); function userSuccess (userData) { let template = Handlebars.compile($('#user-records').html()), compiledHtml = template({user: userData}); $('#user-list').html(compiledHtml); } } 

After numerous tests, I found out that there is no error if the page is reloaded. Got a question how to reboot when changing View Single Page App?

  • 2
    There is a little lack of code, it is unclear what it means to physically "go to another view" and "change view". I can of course strain the crystal ball and assume that the Ajax request is completed and the handler is called when you don’t have such an element in the house, but I cannot say for sure with this code. - Duck Learns to Take Cover
  • one
    Also, if you really have a Single Page App, then still I recommend to take the finished frame. If you really are reluctant to understand the reactor, then at least the old Backbone + Marionette. Otherwise, you will collect the rake trailer and you will not get to the domain tasks on time. - Duck Learns to Take Cover
  • I don't understand the question - L. Vadim

0