0

I am a beginner at the web applications realm and I'm trying to build a simple web site that sends an httprequest (with javascript XMLHttpRequest object). the web page (html) sits on an "HTTP Preview at localhost" server and the servlet sits on another server "Tomcat v7.0 Server at localhost"

When I try to send the http request I get the next error:

XMLHttpRequest cannot load http://localhost:9999/ebookshop/querymp?author=Tan+Ah+Teck&price=50. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin > 'http://localhost:8080' is therefore not allowed access.

My guess is that it happens because I'm trying to access another server but I don't know how to solve it. On eclipse's browser I see the result and that works fine.

matsjoyce
  • 5,744
  • 6
  • 31
  • 38
yuria
  • 541
  • 2
  • 7
  • 22

3 Answers3

0

You need to enable CORS on the server in your case localhost is the one. you need to have this on request header

Access-Control-Allow-Origin: http://localhost:9999

Kiba
  • 10,155
  • 6
  • 27
  • 31
0

So adding "Access-Control-Allow-Origin" helped.. But it doesn't seems right having 2 different servers e.g: 1.HTTP Preview at localhost 2.Tomcat v7.0 Server at localhost

Is there a way combining the "Http Preview server" with the Tomcat server? or it is unnecessary?

yuria
  • 541
  • 2
  • 7
  • 22
-2

Answers to your Question are here

ANSWER

Answer

Answer

Answer

Very important if you do not have idea about this Works for jQuery and Not for Javascript

Community
  • 1
  • 1
MixedVeg
  • 319
  • 2
  • 15