javascript - Why is browser returning error "TypeError: this._input is null" in Firefox (and similar in Chrome

This is the code I am trying out: It runs correctly without any error in jsfiddleTrying to run the sa

This is the code I am trying out: /
It runs correctly without any error in jsfiddle

Trying to run the same via a web-server locally on my puter does not work. The following files are being loaded:

  • index.html
  • app.js

In Firefox I get this error:

TypeError: this._input is null @ .js/handlebars-1.0.0.beta.6.js:364

In chrome I get this error:

Uncaught TypeError:Cannot call method 'match' of null
under match = this._input.match(this.rules[rules[i]]); in handlebars-1.0.0.beta.6.js

There is a very similar problem raised earlier in this link, but seems that it is still open.

So the question is why is this error happening when it works correctly in jsfiddle? What is the correct way to run this locally?

This is the code I am trying out: http://jsfiddle/sbrsK/10/
It runs correctly without any error in jsfiddle

Trying to run the same via a web-server locally on my puter does not work. The following files are being loaded:

  • index.html
  • app.js

In Firefox I get this error:

TypeError: this._input is null @ http://cloud.github./downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js:364

In chrome I get this error:

Uncaught TypeError:Cannot call method 'match' of null
under match = this._input.match(this.rules[rules[i]]); in handlebars-1.0.0.beta.6.js

There is a very similar problem raised earlier in this link, but seems that it is still open.

So the question is why is this error happening when it works correctly in jsfiddle? What is the correct way to run this locally?

Share Improve this question edited May 23, 2017 at 10:26 CommunityBot 11 silver badge asked Sep 27, 2012 at 4:11 boilediceboiledice 331 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

That error means that #entry-template isn't in the DOM when you try to use it:

var source = $("#entry-template").html(); // There is no #entry-template in the DOM here
var template = Handlebars.pile(source);

That means that you end up trying to pile undefined as a Handlebars template and that doesn't work. You can see the error by running this:

http://jsfiddle/ambiguous/LprDR/

with your console open.

The jsfiddle works because you have all your code running after the DOM has been loaded, that's the default jsfiddle behavior.

You probably have a load order problem in your real code, try wrapping it in a $(function() { /*...*/ }) wrapper.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744307162a4567771.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信