Results 1 to 2 of 2

Thread: Fetch API

  1. #1

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,602

    Fetch API

    Hi all.
    I haven't even heard of the Fetch API until today, but I've been thinking about buying a paid service to allow one of my websites to send text messages.
    (I'm aware that I can email text messages, but between the web host and the carrier, they're getting blocked somewhere).
    The paid service uses the Fetch API and I am supposed to drop some Javascript code into my website to send my SMS parameters to their website along with my key so they can send out the text.
    I can't tell if the JS code is supposed to fit into a function and I call the function, or if I just dump it between <script> tags and let it run when the page is built.
    At any rate, I tried it both ways and it consistently gets errors.
    After several back-and-forths with their technical support, they seem to think my site is running old JS, and they made suggestions to modify the JS code, but nothing got it up and running.

    My site is built in classic ASP and usually running Javascript functions is no problem at all.

    My main question is, has anybody used this API from a webpage successfully, and if so, could you post a hollowed out example of where the Fetch code is placed and the code that calls it?
    Ideally, I would like it to run when the form POST event is triggered (when the page refreshes, not onSubmit).
    But I'll take anything you have.

    If it makes a difference, I'll post the code I got (sanitized):

    fetch('https://(their website)', {
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
    phone: '5555555555',
    message: 'Hello world',
    key: '(my key)',
    }),
    }).then(response => {
    return response.json();
    }).then(data => {
    console.log(data);
    });

    The commas that are followed by nothing each throw an error, and if both commas are removed, there is an error on =>, and if I use the older code that tech support sent me, I get an undefined error on JSON.

    Any help is welcome here.
    thanks,
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,807

    Re: Fetch API

    I have heard of the Fetch API and have no idea what it is other than that it's something web based. You say your site is built in classic ASP? Is your version of ASP capable of supporting the version of JavaScript you need?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width