0

此代码片段是 html 5 独立网页的一部分。有人可以告诉我如何更新此代码以要求该人在他们无法访问该网址时检查他们的互联网连接吗?现在它什么都不做,这是不可接受的。

//get grid for station
function insertTideGrid(marker, stationId, defaultCenter) {
    currentMarker = marker;
    currentStationId = stationId;
    if(grids['station'+stationId]) {
        addTextToInfowindow(marker, grids['station'+stationId], defaultCenter);
    } else {
        addTextToInfowindow(marker, '<img src="../images/ajax-loader.gif" /> <br /> Loading...', defaultCenter);
        $.ajax({
            url: 'http://www.mydomain/page.php',
            dataType: 'jsonp',
            type: 'GET',
            data: {'station': stationId, 'json': true},
            success: function(data){
            }
        })
    }
}
4

2 回答 2

1

ajax 函数可以让你精确的错误回调;

$.ajax({
        url: 'http://www.mydomain/page.php',
        dataType: 'jsonp',
        type: 'GET',
        data: {'station': stationId, 'json': true},
        success: function(data){
        },
        error: {
            alert('Please check your internet connection and reload the page');
        }
    })
于 2012-09-03T09:30:29.257 回答
1
//modify your ajax like this

 $.ajax({
            url: 'http://www.mydomain/page.php',
            dataType: 'jsonp',
            type: 'GET',
            data: {'station': stationId, 'json': true},
            success: function(data){
               // do you wat you want here..its OK
            },error:function(msg){
           alert(msg); //you will get the error here
           }
        });
于 2012-09-03T09:31:36.453 回答