I have small ajax problem related to cross domain as i see it.
On localmachine i created html example with some ajax: in registration text field user types \'username\',
For me, It was web api(c# .NET) request and cors was not enabled. Added header for cors on controller and it solved the problem.
[EnableCors(origins: "*", headers: "*", methods: "*")]
You need to use a domain-relative URL in your Ajax request:
/Dinamicki1/UsernameServlet?username=zik
Or a context-relative URL (assuming that the page is served from /Dinamicki1
):
UsernameServlet?username=zik
With regard to "Ajax tutorial for Java", start here: How to use Servlets and Ajax?
I figured out how to solve it from this site:
"To allow directory browsing via Apache Tomcat change the parameter "listings" in the file conf/web.xml from false to true."
Call your page not as C:/Documents and Settings/.../page.html
but as localhost:8080/your_servlet_name
(page is better named index.html
).
This way, you will be able to make AJAX requests to localhost:8080/your_servlet_name/something_else
.
You cannot use AJAX to read replies from other domains.
Your HTML must be on the same server (and same domain, port, and protocol) as the AJAX servlet.
A solution that worked for me was that I had to add "www" to the url! I was using URL Rewrite, so every URL that I had (image, js, get, load, post), I needed to use full url, but it was missing "www"!
The 200 status reported in Firebug does not indicate the validity of the cross-domain ajax call, be it successful or not.
You might want to try using a proxy method to perform the call.
E.g. JavaScript: Use a Web Proxy for Cross-Domain XMLHttpRequest Calls