admin管理员组文章数量:1026073
so I have this code:
;
(function (g) {
var d = document, i, am = d.createElement('script'), h = d.head || d.getElementsByTagName("head")[0], aex = {
"src": '',
"type": "text/javascript",
"async": "true",
"data-vendor": "acs",
"data-role": "gateway"
};
for (var attr in aex) {
am.setAttribute(attr, aex[attr]);
}
h.appendChild(am);
g['acsReady'] = function () {
var aT = '__acsReady__', args = Array.prototype.slice.call(arguments, 0), k = setInterval(function () {
if (typeof g[aT] === 'function') {
clearInterval(k);
for (i = 0; i < args.length; i++) {
g[aT].call(g, function (fn) {
return function () {
setTimeout(fn, 1)
};
}(args[i]));
}
}
}, 50);
};
})(window);
when you run it through the console in Firefox, it'll plain
"SyntaxError: expected expression, got '<'"
However, when you try it out in .html, it works just fine...
what does it do wrong?
so I have this code:
;
(function (g) {
var d = document, i, am = d.createElement('script'), h = d.head || d.getElementsByTagName("head")[0], aex = {
"src": '',
"type": "text/javascript",
"async": "true",
"data-vendor": "acs",
"data-role": "gateway"
};
for (var attr in aex) {
am.setAttribute(attr, aex[attr]);
}
h.appendChild(am);
g['acsReady'] = function () {
var aT = '__acsReady__', args = Array.prototype.slice.call(arguments, 0), k = setInterval(function () {
if (typeof g[aT] === 'function') {
clearInterval(k);
for (i = 0; i < args.length; i++) {
g[aT].call(g, function (fn) {
return function () {
setTimeout(fn, 1)
};
}(args[i]));
}
}
}, 50);
};
})(window);
when you run it through the console in Firefox, it'll plain
"SyntaxError: expected expression, got '<'"
However, when you try it out in http://esprima/demo/validate.html, it works just fine...
what does it do wrong?
Share Improve this question asked Dec 2, 2015 at 22:59 pillarOfLightpillarOfLight 9,01216 gold badges61 silver badges91 bronze badges 3- I just run in Google Chrome's console and Firefox console and it's works. – caballerog Commented Dec 2, 2015 at 23:18
- In Firefox its apparently different – frontend_dev Commented Dec 2, 2015 at 23:21
- chrome silently ignores it but on firefox it still will make the network request as @frontend_dev mentioned – enjoylife Commented Dec 2, 2015 at 23:23
1 Answer
Reset to default 4I think this line is problematic:
"src": '',
So you have in essence a blank src. The error itself indicates that you get some HTML in response, in this case apparently the browser just tries to load the page you are currently on (watch the network panel). But try to use something more meaningful with your src, or leave it out pletely if you just want to create a script tag.
so I have this code:
;
(function (g) {
var d = document, i, am = d.createElement('script'), h = d.head || d.getElementsByTagName("head")[0], aex = {
"src": '',
"type": "text/javascript",
"async": "true",
"data-vendor": "acs",
"data-role": "gateway"
};
for (var attr in aex) {
am.setAttribute(attr, aex[attr]);
}
h.appendChild(am);
g['acsReady'] = function () {
var aT = '__acsReady__', args = Array.prototype.slice.call(arguments, 0), k = setInterval(function () {
if (typeof g[aT] === 'function') {
clearInterval(k);
for (i = 0; i < args.length; i++) {
g[aT].call(g, function (fn) {
return function () {
setTimeout(fn, 1)
};
}(args[i]));
}
}
}, 50);
};
})(window);
when you run it through the console in Firefox, it'll plain
"SyntaxError: expected expression, got '<'"
However, when you try it out in .html, it works just fine...
what does it do wrong?
so I have this code:
;
(function (g) {
var d = document, i, am = d.createElement('script'), h = d.head || d.getElementsByTagName("head")[0], aex = {
"src": '',
"type": "text/javascript",
"async": "true",
"data-vendor": "acs",
"data-role": "gateway"
};
for (var attr in aex) {
am.setAttribute(attr, aex[attr]);
}
h.appendChild(am);
g['acsReady'] = function () {
var aT = '__acsReady__', args = Array.prototype.slice.call(arguments, 0), k = setInterval(function () {
if (typeof g[aT] === 'function') {
clearInterval(k);
for (i = 0; i < args.length; i++) {
g[aT].call(g, function (fn) {
return function () {
setTimeout(fn, 1)
};
}(args[i]));
}
}
}, 50);
};
})(window);
when you run it through the console in Firefox, it'll plain
"SyntaxError: expected expression, got '<'"
However, when you try it out in http://esprima/demo/validate.html, it works just fine...
what does it do wrong?
Share Improve this question asked Dec 2, 2015 at 22:59 pillarOfLightpillarOfLight 9,01216 gold badges61 silver badges91 bronze badges 3- I just run in Google Chrome's console and Firefox console and it's works. – caballerog Commented Dec 2, 2015 at 23:18
- In Firefox its apparently different – frontend_dev Commented Dec 2, 2015 at 23:21
- chrome silently ignores it but on firefox it still will make the network request as @frontend_dev mentioned – enjoylife Commented Dec 2, 2015 at 23:23
1 Answer
Reset to default 4I think this line is problematic:
"src": '',
So you have in essence a blank src. The error itself indicates that you get some HTML in response, in this case apparently the browser just tries to load the page you are currently on (watch the network panel). But try to use something more meaningful with your src, or leave it out pletely if you just want to create a script tag.
本文标签: firefoxjavascript syntax error expected expressiongot 39lt39Stack Overflow
版权声明:本文标题:firefox - javascript syntax error expected expression, got '<' - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745626324a2159883.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论