-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathajaxrequest.html
196 lines (171 loc) · 5.62 KB
/
ajaxrequest.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<!DOCTYPE html>
<html>
<title>AppCenter - Xamarin Webview Samples</title>
<link rel="stylesheet" href="jQueryUI/jquery-ui-1.12.0.custom/jquery-ui.min.css">
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="jQueryUI/jquery-ui-1.12.0.custom/jquery-ui.min.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-81122166-1', 'auto');
ga('send', 'pageview');
</script>
<script>
var jQueryLoaded = false;
function checkForJQuery() {
//if the jQuery object isn't available
if (typeof(jQuery) == 'undefined') {
document.write("<h1>Could not load jQuery on this device (</h1>");
jQueryLoaded = false;
} else {
jQueryLoaded = true;
}
}
window.onload = function () {
checkForJQuery();
if (!jQueryLoaded)
return;
$.ajax({
url: "https://api.github.com/users/xamarin/repos",
statusCode: {
403: function() {
$("#githubRepos").append('<option value="None">Rate Limit Reached ... Sorry :(</option>');
$("#githubRepos").parent().prepend("<div class='ui-state-error'><br>Github Rate Limiting :(<br>" + data.message + "<br><br></div>");
},
404: function() {
alert( "page not found" );
}
}
})
.fail(function() {
//alert( "error" );
})
.always(function() {
//alert( "complete" );
})
.done(function( data ) {
//$("body").html = data.total_count;
if ( console && console.log ) {
console.log( "Sample of data:", data);
}
var sel = $("#githubRepos");
$("#githubReposStargazers").empty();
$("#githubReposStargazersRepo").empty();
sel.empty();
var stargazers;
for (var i=0; i<data.length; i++) {
if (data[i].stargazers_count <= 30) {
stargazers = data[i].stargazers_count;
} else {
stargazers = "30+";
};
sel.append('<option value="' + data[i].name + '">' + data[i].name + ' (Stargazers: ' + stargazers + ')</option>');
}
$("#githubRepos").change();
});
$("#githubRepos").on('change', function() {
var value = $("#githubRepos option:selected").text();
if (value != "" && value != "None") {
//if ($("#githubRepos option:selected").text() != "") {
var url = "https://api.github.com/repos/xamarin/" + $("#githubRepos option:selected").val() + "/stargazers";
var sel = $("#githubReposStargazers");
console.log(url);
$.ajax({
url: url,
statusCode: {
404: function() {
alert( "page not found" );
}
}
})
.fail(function() {
//alert( "error" );
})
.always(function() {
//alert( "complete" );
})
.done(function( data ) {
//$("body").html = data.total_count;
if ( console && console.log ) {
console.log( "Sample of data:", data);
}
sel.empty();
$("#githubReposStargazersRepo").empty();
if (data.length == 0) {
sel.append('<option value="None">None</option>');
$("#githubReposStargazersRepo").append('<option value="None">None</option>');
} else {
for (var i=0; i<data.length; i++) {
sel.append('<option value="' + data[i].login + '">' + data[i].login + '</option>');
}
//$("#githubReposStargazers").change();
}
});
};
});
$("#githubReposStargazers").on('change', function() {
var value = $("#githubReposStargazers option:selected").text();
if (value != "" && value != "None") {
var url = "https://api.github.com/users/" + $("#githubReposStargazers option:selected").val() + "/repos";
var sel = $("#githubReposStargazersRepo");
console.log(url);
$.ajax({
url: url,
statusCode: {
404: function() {
alert( "page not found" );
}
}
})
.fail(function() {
//alert( "error" );
})
.always(function() {
//alert( "complete" );
})
.done(function( data ) {
//$("body").html = data.total_count;
if ( console && console.log ) {
console.log( "Sample of data:", data);
}
sel.empty();
if (data.length == 0) {
sel.append('<option value="None">None</option>');
} else {
for (var i=0; i<data.length; i++) {
sel.append('<option value="' + data[i].name + '">' + data[i].name + '</option>');
}
};
});
};
});
}
</script>
<body>
<!-- Ajax Request ============================================================================================================================================= -->
<div class='section ui-widget ui-corner-all'>
<p class="ui-state-default ui-corner-all ui-helper-clearfix" style="padding:4px;">
<span class="ui-icon ui-icon-contact" style="float:left; margin:-2px 5px 0 0;"></span>
Ajax Request & Results
</p>
<div class='ui-widget-content ui-widget ui-corner-all '>
<p><i>(some of)</i> <b>Xamarin Github Repos:</b> <a href="https://github.com/xamarin" target="_blank">https://github.com/xamarin</a></p>
<select name="githubRepos" id="githubRepos"></select>
<br>
<!-- <div id="githubReposSelected"></div>
<br> -->
<br><b>Selected Repo's Stargazers: </b>
<select name="githubReposStargazers" id="githubReposStargazers"></select>
<br>
<br><b>Selected Stargazer Repos: </b>
<select name="githubReposStargazersRepo" id="githubReposStargazersRepo"></select>
<br><br>
</div>
</div>
<br/>
<br/>
</body>
</html>