0

Javascript newbie here. I have a javascript function that works nested in an html file, I import an external library abaaso, then declare the function and then call it:

<!DOCTYPE html>
<html>
<head>
    <title>title</title>
    <script src="abaaso.js"></script>
</head>

<body>

<script>
    var baseurl = "https://example.com";
    var baseapi = baseurl + "/api/v1/";
    var api_username = "user";
    var api_key = "key";
    var credentials = "?api_username=" + api_username + "&api_key=" + api_key;
    var rawdata = {};

    (function ($$) {

        /* login */
    login = function(username, password) {
    var calledUrl = baseapi + "user/login/" + credentials;
    calledUrl.post(
        function (content) {
            /*console.log("success" + JSON.stringify(content, null, 4));*/
        },
        function (e) {
            console.log("it failed! -> " + e);
        },
        {
                "username": username,
                "password": password

        },
        {"Accept" : "application/json"}
    );
    }

})(abaaso);

login('[email protected]', 'passwd');

</script>
</body>
</html>

I want to put it in an external .js file and import it and only use the call to the function login('[email protected]', 'passwd');. I don't want to import abaaso from the html file but from the new .js.

How can I do that? Is there a particular structure to respect? Do I need to create a global function to the js file?

2
  • What is in abaaso.js? Commented Oct 16, 2013 at 12:12
  • @FritsvanCampen it is a javascript framework abaaso.com Commented Oct 16, 2013 at 13:16

1 Answer 1

1

I don't want to import abaaso from the html file but from the new .js.

You can't do that. However, you can import both abaaso and the new .js:

<head>
  <title>title</title>
  <script src="abaaso.js"></script>
  <script src="new.js"></script>
</head>
Sign up to request clarification or add additional context in comments.

2 Comments

I was looking at this question just now trying to figure it out. Wouldn't it be possible in my case?
Yes, it would be possible, I hadn’t thought about this solution. But it seems me you’re going into unnecessary pain.

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.