0

I want to create a simple AJAX call, based on How to use Servlets and Ajax? answer.
The servlet processes the request (it can print on console in the doGet() function), but nothing happens on the client side. Chrome error message is:

XMLHttpRequest cannot load http://localhost:8080/package/servlet. Origin null is not allowed by Access-Control-Allow-Origin.

Thanks!

Community
  • 1
  • 1
Anvar
  • 404
  • 2
  • 9
  • 19
  • 1
    So the servlet runs on a different domain than the page sending the ajax request? Is this absolutely necessary? – BalusC Mar 27 '12 at 17:05
  • I run the html from the local storage (C:). Is that a problem? How should I run it? – Anvar Mar 27 '12 at 17:39

2 Answers2

0

It looks like the browser side is rejecting the AJAX request/response based on Cross Origin Resource Sharing. That is where the Access-Control-Allow-Origin header is coming from. Give this thread a read for some hints on how to approach this problem.

Community
  • 1
  • 1
D.Shawley
  • 58,213
  • 10
  • 98
  • 113
0

I run the html from the local storage (C:). Is that a problem? How should I run it?

That is definitely a problem. You should request the HTML over HTTP instead. Your target endusers also won't run HTML from the local disk file system, right?

Open http://localhost:8080/package/filename.html in your browser.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Oh yeah, you were right! I'm running now the html on the same domain, and it works fine. Thanks for the hint! – Anvar Mar 27 '12 at 17:49