doctype html html lang en head meta charset utf-8 title JSONP demo tit

 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSONP demo</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
</head>
<body>
<script>
$(document).ready(function(){
$('#target').click(function(){
console.log("Click!");
$('#target').prop("disabled", true);
$('#target').text("Loading...");
var testAPI = "http://127.0.0.1:8888?callback=?";
$.getJSON( testAPI, {
tag: "w_test_tag",
package: "w_test_pkg",
date: "some_date"
})
.done(function( data ) {
if (data.response == "success") {
console.log("YES");
$('#test').append("<p>" + data.message + "</p>");
} else {
console.log("NO");
}
})
.fail(function() {
console.log( "Error" );
$('#test').append("<p>General error</p>");
})
.always(function() {
console.log( "Completed" );
$('#target').prop("disabled", false);
$('#target').text("Test it");
});
});
});
</script>
<div id="test">
<button id="target">Test it</button>
</div>
</body>
</html>