.This is the code of my java script.I want to add error and timeout to my function when calling json with ajax...how can i do that..i am new to this..plz help..i am stuck..
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link href="js/jquery.mobile-1.4.2.min.css" rel="stylesheet" type="text/index.css"/>
<title>Hello World</title>
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.4.2.min.js"></script>
<script>
$('#reposHome').bind('pageinit', function(event) {
loadRepos();
});
function loadRepos() {
$.ajax("https://api.github.com/legacy/repos/search/javascript").done(function(data) {
var i, repo;
$.each(data.repositories, function (i, repo) {
$("#allRepos").append("<li><a href='https://github.com/" + repo.username + "/" + repo.name + "'>"
+ "<h4>" + repo.name + "</h4>"
+ "<p>" + repo.username + "</p></a></li>");
});
$('#allRepos').listview('refresh');
setTimeout(function(){
loadRepos();
}, 5000);
})
.fail(function (xhr, ajaxOptions, thrownError) {
alert(xhr.statusText);
alert(xhr.responseText);
alert(xhr.status);
alert(thrownError);
});
}
</script>
</head>
<body>
<div data-role="page" id="pagetwo">
<div data-role="header">
<h1>My First page</h1>
</div>
<div data-role="main" class="ui-content">
<p>Welcome to My page</p><br>
<ul id="allRepos" data-role="listview" data-filter="true">
</ul>
</div>
<div data-role="footer">
<h1>Footer Text</h1>
</div>
</div>
</body>
</html>
Here i have also added the html part of my code..