I have been attempting to access my basic web API created in Jersey, which returns the following data:
[
{
"id": 1,
"name": "Facebook",
"userName": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f4959697b49399959d98da979b99">[email protected]</a>",
"password": "Qwerty@123"
}
]
The JSONP request I am using appears as follows:
this.jsonp.get('http://localhost:8080/api/rest/domains?callback=JSONP_CALLBACK')
.toPromise()
.then(response => console.log("Success: " + response),
err => console.log("Failed: " + err));
Despite this, I am seeing the following message in the console output:
Failed: Response with status: 200 Ok for URL: http://localhost:8080/DomainServiceApi/rest/domains?callback=ng_jsonp.__req0.finished
I cannot seem to pinpoint the issue.
EDIT: Thankfully, I managed to resolve my problem. By reverting back to using the http.get method and eliminating unnecessary in-memory web API imports, I received an error suggesting that "Access-Control-Allow-Origin" should be included in the response headers on the server side. After adding this header to my Jersey Web API, everything began functioning correctly.
If you are utilizing Jersey, refer to How to add headers in Jersey response for guidance.