2

Hope you’re doing well!

If you could, I’d like help with this: I’m very new to javascript, and have a question. How do I trigger a webhook URL by javascript (without loading the page)? In this case, the webhook responds “silently”, and is used just to kick off Zapier events. All that really needs to happen is to trigger the URL on pageload through javacsript (the javascript containing the webhook trigger). As long as the URL is triggered, that’s really all I’m looking for.

Really Appreciate your help. : )

Thanks! Vince

I've tried the window.location parameter, but it doesn't seem to be triggering the webhook URL.

<script>
window.location = '[webhook url here]'
<script>

Actual Results: Code is not triggering the webhook URL on pageload.

Thanks for your help! - Vince

1 Answer 1

4

You can send a request to a URL with the fetch API.

fetch('http://example.com');

This should be enough to 'trigger' (load) the URL and it won't make the browser actually visit the page, just send a request to it.

The fetch call returns a promise that resolves to a response. So if you want to log the response you get you can do it like this: *Example taken from MDN. In this example the fetch call returns JSON data.

fetch('http://example.com/movies.json')
  .then(function(response) {
    return response.json();
  })
  .then(function(myJson) {
    console.log(JSON.stringify(myJson));
  });

You can read more about how to use it here:

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

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

2 Comments

Hey, Azer, thanks for your informative answer. That is what I was looking for. Thanks for your help! I appreciate you also explaining how to return JSON data on "fetch".
@VinceJ No problems! Glad it helped. Please consider marking the answer as correct to help other users find solutions to their problems.

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.