You really haven't provided enough context to really know what the issue is with your request, you need to look at the
exception
variable and look at what information it's providing you. Have you tried debugging this Javascript in the browser, stepping through the code line-by-line to see what's happening?
That being said, if you're trying to issue an AJAX request to another website you need to be aware of
cross-origin (CORS)[
^] restrictions that websites may put in place. The website may choose to prevent external websites from making these sorts of requests, and your browser will honour that decision. You would receive errors when attempting to make API requests as the server rejects them.
If you own the API yourself (for example, running it on your local machine or have access to wherever the server is being hosted, and/or the source code of the application) you may need to do some additional configuration to allow external connections.
Enable Cross-Origin Requests (CORS) in ASP.NET Core | Microsoft Docs[
^]
Getting Started | Enabling Cross Origin Requests for a RESTful Web Service[
^]