ajax problem - 200 OK in firebug but red message with no response body

早过忘川 提交于 2019-12-03 22:23:55

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", well there's actually not really one. Those are just two separate technologies. I would however recommend to get yourself started with jQuery (for the client side) and Google Gson (for the server side) and JSON (as communication language between client and server).

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.

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

Gleb

I figured out how to solve it from this site:

  1. "To allow directory browsing via Apache Tomcat change the parameter "listings" in the file conf/web.xml from false to true."

  2. 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.

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"!

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: "*")]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!