locked
Error RRS feed

  • Question

  • User1979860870 posted

    Hi

    Access to XMLHttpRequest at 'http://localhost:40991/api/Employees' from origin 'http://localhost:33565' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Api.WebForm1" %>
    
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <title>Product App</title>
    </head>
    <body>
    
      <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.min.js"></script>
      <script>
          var uri = 'http://localhost:40991/api/Employees';
    
        $(document).ready(function () {
          // Send an AJAX request
          $.getJSON(uri)
              .done(function (data) {
                  alert("hi");
                // On success, 'data' contains a list of Employees.
                $.each(data, function (key, item) {
                  // Add a list item for the product.
                  $('<li>', { text: formatItem(item) }).appendTo($('#employees'));
                });
              });
        });
    
        function formatItem(item) {
          return item.Id + ': $' + item.Name;
        }
    
      </script>
    </body>
    </html>

    Thanks

    Thursday, February 18, 2021 2:24 PM

All replies