开发者

notify user when wifi, or 3g 4g network get lost jquery or javascript

开发者 https://www.devze.com 2023-03-29 01:27 出处:网络
we have web site which is optimized for mobile phone. we do qute frequent ajax requestes and some time an event get rigered from a back end.

we have web site which is optimized for mobile phone. we do qute frequent ajax requestes and some time an event get rigered from a back end.

now the problem is how to properly manage when network connection get lost.

can we create a custom event where it will be triggered when a connection get lo开发者_如何学运维st using jquery?


Try this:

function doIhaveInterWebs(){
  $.ajax({
    url: "test.txt",
    success: function() {return true}
    error: function(){return false}
   });
 }


use following code.

$(document).ready(function () {
   if (!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
   }
});

    function endRequestHandler(sender, args) {
        if (args.get_error() != undefined) {
            var errorMessage;
            if (args.get_response().get_statusCode() == '200') {
                errorMessage = args.get_error().message;
            }
            else {
                // Error occurred somewhere other than the server page.
                errorMessage = "Error Message";
            }
            args.set_errorHandled(true);
            $get('ErrorMessage').innerHTML = errorMessage;
        } else {
            // no error occur
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消