I have an html code that calls my agent, but if I do not open a localhost,,..., it does not work. although I know it can work severlessly

luis rodriguez 0 Reputation points
2024-06-18T20:07:39.19+00:00

I have the code below

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Form Example</title>
</head>
<body>
  <h1>Form Example</h1>
 
  <form>
    <label for="input-field">Name:</label>
    <input type="text" id="input-field" placeholder="Enter your name">
    <button type="submit">Submit</button>
  </form>
 
  <script>
    const form = document.querySelector('form');
    const input = document.querySelector('#input-field');
 
    form.addEventListener('submit', async (e) => {
      e.preventDefault();
 
      const value = input.value;
 
      try {
        const response = await fetch(
          `https://ryseagentapp.azurewebsites.net/api/HttpTrigger1?code=vRtxxW3lo1O7bPSxxlgHifpYYwevm-aEpEsmEclCOKFXAzFuY6Ae_Q%3D%3D&name=${value}`
        );
 
        if (response.ok) {
          const data = await response.text();
          console.log(data);
          alert(data);
        } else {
          console.error('Error:', response.status, response.statusText);
          alert('An error occurred: ' + response.statusText);
        }
      } catch (error) {
        console.error('Fetch error:', error);
        alert('An error occurred while fetching data.');
      }
    });
  </script>
</body>
</html>

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,542 questions
0 comments No comments
{count} votes