0
我的這些論壇的第一篇文章:)使用ping來確定使用Javascript的IF語句?
這是在移動瀏覽器(在這種情況下android)工作。在知道使用哪個功能之前,我需要檢查計算機是否處於開啓狀態。
有沒有一種方法可以確定它的網絡狀態並運行相應的功能?現在,我只是有測試的消息。 (navigator.notification.alert是用於在移動設備上顯示消息的科爾多瓦方法)
我已經編好了這段代碼,有沒有什麼辦法可以使這個工作,我做了一些谷歌搜索無濟於事。
請注意,這是在本地網絡上工作。
function isOn() {
$.ajax({
url : 'http://192.168.x.xxx' , //x.xxx being the client ip
success : function() {
navigator.notification.alert(
'The computer is on.', //Message body
alertDismissed, //Callback
'The Computer is On', //Title
'Yes' //Button Label
);
},
error : function() {
navigator.notification.alert(
'The computer is off.', //Message body
alertDismissed, //Callback
'The Computer is Off', //Title
'Yes' //Button Label
);
}
});
};
<a onclick="isOn();">Test</a>
那些代碼不起作用?它是否在控制檯中給出任何錯誤? – sachleen 2012-08-13 15:01:12
可能重複的[Javascript:檢查服務器是否在線?](http://stackoverflow.com/questions/5224197/javascript-check-if-server-is-online) – sachleen 2012-08-13 15:01:56
這是另一個SO相關的問題從JS :http://stackoverflow.com/questions/4954741/how-to-ping-ip-addresses-using-javascript – jwatts1980 2012-08-13 15:02:54