有什么方法来检查服务器在jQuery + phonegap的可达性测试 [英] Is there any way to check reachability test of server in jQuery +phonegap

查看:96
本文介绍了有什么方法来检查服务器在jQuery + phonegap的可达性测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有任何方法来检查服务器的可达性测试。如果应用程序无法连接服务器,那么它会显示警报?是有任何东西的方法来检查..
我检查互联网连接。如果没有连接,然后我显示一个警报。但如果有一个连接,但没有服务器的可达性,我怎么能处理这个。?
我检查像这样的连接状态..

Is there any way to check reachability test of server .If application not able to connect server then it show a alert? is there any thing method to check.. I check the internet connection .If there is no connection then i am showing a alert .But if there is an connection but there is no reachability of server than how can i handle this.? I am checking like this connection status..!!

setInterval(function () {
    connectionStatus = navigator.onLine ? 'online' : 'offline';
    if(connectionStatus=="offline"){
        // alert("There is no connection");
    }
}, 100);



$.ajax({url: "192.168.12.171",
        dataType: "jsonp",
        statusCode: {
            200: function (response) {
                alert('status 200');
            },
            404: function (response) {
                alert('status  404 ');
            }
        }                        
 });


推荐答案

要测试您的服务器是否正常运行,连接到它并检查状态按钮:

To test if your server is up you will need to connect to it and check status massage:

$.ajax('LINK GOES HERE', {
  statusCode: {
    404: function() {
      alert('Not working');
    },
    200: function() {
      alert('Working');
    }
  }
});

工作jsFiddle示例: http://jsfiddle.net/Gajotres/PMrDn/47/

Working jsFiddle example: http://jsfiddle.net/Gajotres/PMrDn/47/

$.ajax({url: "http://api.themoviedb.org/2.1/Movie.search/en/json/23afca60ebf72f8d88cdcae2c4f31866/The Goonies",
        dataType: "jsonp",
        statusCode: {
            200: function (response) {
                alert('status 200');
            },
            404: function (response) {
                alert('status  404 ');
            }
        }                        
 });



EDIT:



/ p>

EDIT :

Use this:

$.ajax({url: "http://192.168.12.171",
        type: "HEAD",
        timeout:1000,
        statusCode: {
            200: function (response) {
                alert('Working!');
            },
            400: function (response) {
                alert('Not working!');
            },
            0: function (response) {
                alert('Not working!');
            }              
        }
 });

工作范例:http://jsfiddle.net/Gajotres/PMrDn/48/

这篇关于有什么方法来检查服务器在jQuery + phonegap的可达性测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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