Home > Net >  Post request from html using javascript
Post request from html using javascript

Time:09-22

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 .

CodePudding user response:

look at this https://www.npmjs.com/package/axios

Promise based HTTP client for the browser and node.js

CodePudding user response:

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