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

前端 未结 6 1732
一个人的身影
一个人的身影 2021-02-18 16:21

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\',

相关标签:
6条回答
  • 2021-02-18 16:33

    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: "*")]
    
    0 讨论(0)
  • 2021-02-18 16:37

    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?

    0 讨论(0)
  • 2021-02-18 16:39

    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.

    0 讨论(0)
  • 2021-02-18 16:44

    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.

    0 讨论(0)
  • 2021-02-18 16:45

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

    0 讨论(0)
  • 2021-02-18 16:46

    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

    0 讨论(0)
提交回复
热议问题