Post request from html using javascript

Viewed 27

I have <script>var foo=bar;</script> .I want to write a fucntion in the same script tag which sends data (bar) to http://example.com/get-data/. I don't know much knowledge about js.

<body>
    <script>
    var hash_token = window.location.hash;
    removed_hash_token=hash_token.slice(1);
    alert(removed_hash_token)
    get_token_url="http://localhost:8000/"
    </script>
</body>

see I have hash fragment after login google redirecting in url,so I take hash and remove it and I want to send this to backend .

2 Answers

using what @SwaD suggested I came up with answer,thank you to guide me.

answer:

<script>
    var hash_token = window.location.hash;
    removed_hash_token = hash_token.slice(1);
    alert(removed_hash_token);
    axios.post("http://localhost:8000/calender/", { "token_hash": removed_hash_token })
        .then(function (response) {
            console.log(response);
        })
        .catch(function (error) {
            console.log(error);
        });
</script>
Related