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?