I am trying to get a json response from an API request. I am using jetty servlet, and my GET request works when I try it in post man.
However I am trying to create a website that will query my API but I get the error:
Failed to load localhost:49000/api/coin/help: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
My js code looks like:
$(function () {
$.ajax({
type: 'GET',
url: 'localhost:49000/api/coin/help',
success: function(data) {
console.log('success', data);
}
});
});
Can someone please tell me how I can get a similar response as if I was using postman. I have been stuck on this for days and finally had to ask here, I know there are similar questions/answers however it has not helped me.
XML file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.mycompany.jerseytutorial</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>