如何检查使用的JavaScript原生的Andr​​oid 2.1浏览器服务器连接? [英] How to check for connectivity with server using javaScript from native Android 2.1 browser?

查看:121
本文介绍了如何检查使用的JavaScript原生的Andr​​oid 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服务我的服务器上。这铬工作正常的上网本,但原生的Andr​​oid浏览器返回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()写(输出);
    }

这篇关于如何检查使用的JavaScript原生的Andr​​oid 2.1浏览器服务器连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆