I am using Java Restfull Webservice which is dumping Data in postgres SQL. Java WebService function working perfectely.Function is like below
@Path("/db")
public class DBOperaions {
@POST
@Path("/insert")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public String InsertDBData(@PathParam("hname") String hname,
@PathParam("hdates") String hdates,
@PathParam("hremark") String hremark,
@PathParam("isDelete") boolean isDelete,
@PathParam("created_date") String created_date,
@PathParam("updated_date") String updated_date) {
//Data Dumping Code
}
}
Now i am trying to access this function from Jquery Ajax like below
var obj = { hname: $("#txtRuleName").val(), hdates: $("#txtRuleDates").val(), hremark: $("#txtRuleRemark").val(), isDelete: false, created_date: 'CURRENT_TIMESTAMP', updated_date: 'CURRENT_TIMESTAMP' };
$.ajax({
type: "POST",
contentType: "application/json",
dataType: "json",
xhrFields: {
withCredentials: true
},
url: "http://localhost:8015/PostGresTestDB/rest/db/insert",
data: JSON.stringify(obj),
success: function (data, textStatus, jqXHR) {
alert('Data Inserted successfully...');
},
error: function (jqXHR, textStatus, errorThrown) {
alert('generateReportFromMR:Error in processing!');
//alert(jqXHR);
}
});
Webservice runs on tomcat server with http://localhost:8015/PostGresTestDB/rest/db/insert and web page running on http://localhost:42229/index.html
I am getting following error
XMLHttpRequest cannot load http://localhost:8015/PostGresTestDB/rest/db/insert. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:49927' is therefore not allowed access.
I tried CORS but no success.
Can Anybody tell me what exactly what i want to do for this?