Here is the server controller file, which is exposing a GET method, which returns a user object.
And here is a client side script, which get this data from another web page using JQuery Ajax method.
Without enabling CORS, the ajax request will fail, it will throw some exception like this.
To enable CORS in ASP.NET 5, you need to install the “Microsoft.AspNet.Cors” package to the project.json. And you need to configure CORS in the Startup.cs file.
Here you are Adding the core support and configure ASP.NET to accepts requests from the configured URL. Now if you run the code, you will see “[object Object]” instead of “error” in the label.
Happy Programming :)