如何检查使用的JavaScript原生的Android 2.1浏览器服务器连接?
我建立,需要被在线或离线时要无缝工作的Web应用程序。对于这种需要能够为检查我与服务器连接即可。
I am building a web application that needs to be working seamless when being online or off line. For this need to be able to check my connection with the server.
这是要支持的主要设备是iPhone3的+ 4,iPad的,与Chrome和Android 2.1+上网本。
The main devices that are to be supported are iphone3+4, ipad, a netbook with chrome and android 2.1+.
的 navigator.onLine
不正是我期待的。这是不可靠的,只检查,如果你有连接,如果没有您连接到特定的服务器。
The navigator.onLine
is not exactly what I am looking for. This is unreliable and only checks if you have connectivity, not if you are connected to a specific server.
我试过 jQuery.getJSON
连接到平web服务我的服务器上。这铬工作正常的上网本,但原生的Android浏览器返回null。 IPOD TOUCH根本不进行任何操作。
I tried jQuery.getJSON
to connect to a ping web-service on my server. This works fine in chrome on the netbook but the native android browser returns null. Ipod touch doesn't do anything at all.
我可以使用一些帮助,这..
I could use some help with this..
它毕竟曾与同源策略(见注释)做。结果
这是按使用JSONP解决
It after all had to do with the 'same origin policy' (see comments).
This was resolved by using JSONP.
但奇怪的是,它看起来像我处理相同的域名,但奥凯这里的code ...
The strange thing is that it looks like I am dealing with the same domain, but oke here the code...
客户端:结果 jQuery.getJSON(URL?回调=?,功能(数据){
搜索
//做一点事
});
服务器端:结果 @RequestMapping(值=URL,方法= RequestMethod.GET)
公共无效平(HttpServletRequest的请求,HttpServletResponse的响应)
抛出IOException
字符串输出=的request.getParameter(回调)+({0:1});;
response.setContentType(文/ JavaScript的);
。response.getWriter()写(输出);
}