2012-09-03 6 views
0

이 코드 단편은 HTML 5 독립형 웹 페이지의 일부입니다. 다른 사람이이 코드를 업데이트하여 URL에 액세스 할 수없는 경우 인터넷 연결을 확인하도록 요청할 수 있습니까? 지금 그것은 아무것도하지 않으며 그것은 받아 들일 수 없습니다.ajax/json 가져 오기 오류 처리

//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){ 
      } 
     }) 
    } 
} 

답변

1

ajax function은 정확한 콜백을 제공합니다.

$.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'); 
     } 
    }) 
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 
      } 
     });