2017-06-01 3 views
-2

Wie kann ich Benutzer warnen, wenn sie den Server

var serviceURL = "http://mywebsite.com/mobile/"; 
 

 
var employees; 
 

 
$(window).load(function() { 
 
\t setTimeout(getEmployeeList, 100); 
 
}); 
 

 
function getEmployeeList() { 
 
\t $.getJSON(serviceURL + 'getemployees.php', function(data) { 
 
\t \t $('#employeeList li').remove(); 
 
\t \t employees = data.items; 
 
\t \t $.each(employees, function(index, employee) { 
 
\t \t \t $('#employeeList').append('<li><a href="reportlist.html?id=' + employee.id + '">' + 
 
\t \t \t \t \t '<img src="pics/' + employee.picture + '" class="list-icon"/>' + 
 
\t \t \t \t \t '<p class="line1">' + employee.firstName + ' ' + employee.lastName + '</p>' + 
 
\t \t \t \t \t '<p class="line2">' + employee.title + '</p>' + 
 
\t \t \t \t \t '<span class="bubble">' + employee.reportCount + '</span></a></li>'); 
 
\t \t }); 
 
\t \t setTimeout(function(){ 
 
\t \t \t scroll.refresh(); 
 
\t \t }); 
 
\t }); 
 
}
Zugriff auf nicht in der Lage Mein Problem mit meinem Skript ist, dass jedes Mal, wenn ich versuche, Server zu erreichen, und es ist nach unten i meine Anwendung mag, dass der Alarm Menschen sein Server ausgefallen ist jetzt

+0

Ihre Frage ist sehr unklar. Was machst du? Wie machst du es? Ist es eine Webseite/Web App? – Clijsters

+1

Verwenden Sie stattdessen "$ .ajax" und überprüfen Sie die Dokumente auf einen Fehler. –

+0

Verwenden Sie den Handler .fail() –

Antwort

0

var serviceURL = "http://mywebsite.com/mobile/"; 
 

 
var employees; 
 

 
$(window).load(function() { 
 
\t setTimeout(getEmployeeList, 100); 
 
}); 
 
// Use the ajaxError method to handle your error 
 
$(document).ajaxError(function(event, request, settings) { 
 
//Then you can use the .hide() to hide div alert users for error 
 
\t $('#errorserver').hide(); 
 
\t alert("Error accessing the server"); 
 
}); 
 

 
function getEmployeeList() { 
 
//Then you can use the .show() to show loading 
 
\t $('#errorserver').show(); 
 
\t $.getJSON(serviceURL + 'getemployees.php', function(data) { 
 
    //Then you can use the .hide() 
 
\t \t $('#errorserver').hide(); 
 
\t \t $('#employeeList li').remove(); 
 
\t \t employees = data.items; 
 
\t \t $.each(employees, function(index, employee) { 
 
\t \t \t $('#employeeList').append('<li><a href="reportlist.html?id=' + employee.id + '">' + 
 
\t \t \t \t \t '<img src="pics/' + employee.picture + '" class="list-icon"/>' + 
 
\t \t \t \t \t '<p class="line1">' + employee.firstName + ' ' + employee.lastName + '</p>' + 
 
\t \t \t \t \t '<p class="line2">' + employee.title + '</p>' + 
 
\t \t \t \t \t '<span class="bubble">' + employee.reportCount + '</span></a></li>'); 
 
\t \t }); 
 
\t \t setTimeout(function(){ 
 
\t \t \t scroll.refresh(); 
 
\t \t }); 
 
\t }); 
 
}
//Add this div to your html page 
 

 
    <div id="errorserver"/><img src="image/loading.png" alt="Loading please wait.."></div>

0

Sie haben Fehler Methode .fail zu handhaben:

$.getJSON(serviceURL + 'getemployees.php', function(data) { 
    // ... your implementation 
}).fail(function (err) { 
    // ... this callback will be invoked 
    // ... in case any error of the server 
}); 
Verwandte Themen