Josh Deshazer
Josh Deshazer

Reputation: 91

Uncaught syntaxError unexpeted token

I am getting the below error when I try to import my function into my web forms script tab of a page. I made a js page that did this ajax to get a jwt token

function getJwtToken() {
    var user = "myuser";
    var token = "";
    var pass = "mypass";
    var xhttp = new XMLHttpRequest(); 
    xhttp.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
            token = this.responseText;
            sessionStorage.setItem("token", token);
        }
    }
    xhttp.open("POST", "https://localhost:44377/api/auth/token", true);
    xhttp.setRequestHeader('Authorization', 'Basic ' + window.btoa(user + ':' + pass));
    xhttp.send();
}

export { getJwtToken }; 

then in the page that I need to get the token I was just trying to call this code by importing this function then calling it.

  <script type="text/javascript">
        import {getJwtToken} from "../../APIChecks.js';

        getJwtToken();
</script>

this is inline JavaScript in a web forms aspx page and I am not sure if you can do this. I thought with the new JavaScript this is something you can do now but I get the above error any help would be greatly appreciated.

Upvotes: 1

Views: 59

Answers (1)

santialur
santialur

Reputation: 235

on line:

"../../APIChecks.js';

Check out the last ' , that should be a "

And use

<script type="module"> 

instead of

<script type="text/javascript">

Upvotes: 1

Related Questions