-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathexample.html
43 lines (37 loc) · 1.1 KB
/
example.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
<!doctype html>
<html>
<head>
<title>Lightweight-JSONP Example</title>
<script src="jsonp.js"></script>
</head>
<body>
<ul id="example"></ul>
<script>
JSONP.init({
error: function(ex){
console.log("Failed to load : " + ex.url);
},
timeout: 3000 //timeout in millis before error callback will be called if not yet completed
});
function the_callback(data) {
var example = document.getElementById('example'),
item = null, li = null;
if ( data && data.length > 0 ) {
for ( var i in data ) {
if ( data.hasOwnProperty(i) ) {
item = data[i];
li = document.createElement('li');
li.innerHTML = "<h3>"+item.title+"</h3><p>"+item.description+"</p>";
example.appendChild(li);
}
}
}
}
JSONP.get('sample-data.js', {param1:'123'}, function(data){
console.log("Received data: ", data)
}, 'the_callback');
//Uncomment the following call will trigger the error callback and alert the failing url.
//JSONP.get('not-existing-url');
</script>
</body>
</html>