问题描述
我小的AJAX的问题涉及到跨域,因为我看到了。
I have small ajax problem related to cross domain as i see it.
在LOCALMACHINE我创建了一些Ajax的html例子:在注册文本字段用户输入用户名,在每次击键阿贾克斯将其发送到本地的Tomcat,在那里,如果已使用Servlet检查该用户名 和发送采取REPONSE回来了。
On localmachine i created html example with some ajax:in registration text field user types 'username',on every keystroke ajax sends it tolocal Tomcat, where servlet checks if that username is already used and sends 'taken' reponse back.
在本地主机上一点问题都没有。当我输入使用用户名的servlet将采取的回应和浏览器显示出来。
No problem on localhost at all.As soon as i type used 'username' servlet sends 'taken' responseand browser displays it.
但是,当我把测试HTML页使用Ajax在远程机器上(有些免费托管在远程网络上)发送验证请求在我的本地的Tomcat,连接而成,在Tomcat的控制台我看到的要求正在添加,在萤火虫在Mozzila这是控制台输出中:
But, when i put test html page with ajaxon remote machine (some free hosting on remote network)that sends validation request on my localhost Tomcat,connection is made,in Tomcat console i see request comming,and in firebug in Mozzila this is Console ouput:
GET http://89.216.182.25:8080/Dinamicki1/UsernameServlet?username=zik 200 OK
...但在应对标签没有servlet响应''截取在萤火虫的消息是红色
...but in response tabthere is not servlet response 'taken'and message in firebug is in red color
所以服务器沟通好,没有防火墙的问题,反应是 200 OK
但是,响应主体是空的。
So servers communicate well, no firewall problems, response is 200 OK
But response body is empty.
任何想法在firebugs这个红色的消息是什么呢?
Any ideas what this red messages in firebugs are?
非常感谢你提前。
如果有人可以推荐一些严重的ajax教程的Java这将是非常美联社preciated:)
And if anyone can recommend a some serious ajax tutorial for javait will be highly appreciated :)
推荐答案
您需要在Ajax请求使用域相对网址:
You need to use a domain-relative URL in your Ajax request:
/Dinamicki1/UsernameServlet?username=zik
或上下文相关的URL(假定页面被从 / Dinamicki1
):
UsernameServlet?username=zik
对于阿贾克斯教程Java的,以及实际上有没有真正之一。这些仅仅是两种不同的技术。不过,我建议让自己开始使用 jQuery的(用于客户端)和(服务器端)和 JSON (客户端和服务器之间的通信语言)。
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).
这篇关于AJAX的问题 - 200萤火,但红色消息没有响应主体确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!