2

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 complain

"SyntaxError: expected expression, got '<'"

However, when you try it out in http://esprima.org/demo/validate.html, it works just fine...

what does it do wrong?

3
  • I just run in Google Chrome's console and Firefox console and it's works. Commented Dec 2, 2015 at 23:18
  • In Firefox its apparently different 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 Commented Dec 2, 2015 at 23:23

1 Answer 1

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 completely if you just want to create a script tag.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah and seriously, explain when you downvote. I hate that and I will just stop trying to help if that continues that way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.