最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

firefox - javascript syntax error expected expression, got '<' - Stack Overflow

matteradmin5PV0评论

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
Add a ment  | 

1 Answer 1

Reset to default 4

I 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.

Post a comment

comment list (0)

  1. No comments so far