Ajax call using Javascript

Trying to call a REST webservice correctly using Ajax from javascript and landing with some error message.Am I doing the following correctly?

$.ajax({
  type: "GET",
  url: "http://localhost:9090/JAX-RS_examples/rest/HelloWorld/sayHello",
  success: function(data) {
    alert(data);
  },
  error: function(data) {
    alert("some error");
  }
});

I have tested the URL separately and it’s returning results on the browser. So there’s something wrong in making the Ajax call that I am doing. Please let me know what could be the problem. Thanks

Thanks. Any other way to overcome this problem?

any alternative to this if what I am doing isn’t possible?

There is also the server side proxy method.

https://developer.yahoo.com/javascript/howto-proxy.html

This page gives specific steps to implement CORS into your web page: https://www.html5rocks.com/en/tutorials/cors/ Don’t give up too quickly!

What is running on http://localhost:9090 ?
And what language is it written in?

Edit: JAX would probably indicate Java. In this case I would google “How to add CORS to Java web app” or something similar.

1 Like

Thanks. The CORS handling would require enabling Access-Control-Allow-Credentials: true on the Apache server. Is it a good idea to enable it or are there any security related risks associated with it?

JBOSS is running on http://localhost:9090. I believe CORS handling would require enabling the credentials as I mentioned in my above post. I am wondering if it could be any kind of security risk?

Considering the acronym stands for Cross Origin Resource Sharing and it requires being explicitly enabled, I’m prone to think it must have some risk. At least for those that don’t understand the risk AFAIK it isn’t an “on or off” but there are various ways to “tune” it for only as much as is needed.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.