Q:

Unable to perform ajax api call

My html page runs on the url specified below, from my html page i want to hit my rest api controller on a button click. But there is an error occuring since the api is not being called and the main spring boot application is getting started successfully on http port 8080.
URL
file:///C:/Users/PF077060/Downloads/project/project/UI%20design/html/Release.html

Ajax Code:

<script >
$(document).ready(function(){
    $("#btn").click(function(event){
        event.preventDefault();
        alert("AJAX request successfully completed");

        ajaxpost();
      });
      function ajaxpost()
      {
          console.log("formData1");  
          var formdata=
          {
                  name:$("#name").val(),
                inputcutoff:$("#inputcutoffdate").val(),
                releasedate:$("#releaseDate").val(),
                    status:$("#status").val(),                  
          };
          //alert("Changed into json format");
          console.log(formdata);
          $.ajax({
              type : "POST",
              contentType : "application/json", 
              url : "localhost:8080/" + "release/addrelease/",
              data : formdata,
              success : function(result)
              {
                alert(result.name);  
                window.location="Main.html";

              },
              error : function(e)
              {
                  alert("Error");
                  console.log("ERROR: ",e);
              }
         });
         resetdata();
      }
      function resetdata(){
          $("#name").val("");
          $("#inputcutoffdate").val("");
          $("#releaseDate").val("");
          $("#status ").val("");
      }
    });
</script>

Error
Access to XMLHttpRequest at 'localhost:8080/release/addrelease/' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
Any help will be appreciated

A:

This error was occurring because the CrossOrigin annotation wasn't specified in the controller class and the url in the Ajax call must start with http:localhost:8080 and so on. 
**In the controllers**
@Crossorigin(origin="*")

**In the ajax call**
url: "http\localhost:8080\\{url were user want to get connected}"

Then the API shouldn't return a null value, the work of the API is to always process the information and should return some value to the client side. 
These were the changes which I made and my ajax call was also successful

