-
Notifications
You must be signed in to change notification settings - Fork 0
/
jQueryJson.html
82 lines (74 loc) · 2.55 KB
/
jQueryJson.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
<html>
<head>
<script src="jquery-3.1.1.js"></script>
<script>
$(document).ready(function(){
/* $.ajax({
type:"GET",
url:"http://localhost:8080/JerseyMessaging/webapi/messagesJson",
datatype:"json",
success:function(jsondata){
alert(jsondata);
}
});
ANOTHER WAY
$.ajax({
//Force to Handle it as Text
url: "http://localhost:8080/JerseyMessaging/webapi/messagesJson",
dataType: "text",
success: function(data) {
//data downloaded so we call parseJSON function
//and pass downloaded data
var json = $.parseJSON(data);
//now json variable contains data in json format
//let's display a few items
for (var i=0;i<json.length;++i)
{
alert(json[i].author);
}
}
});
Another Way
$.ajax({
type: 'GET',
url: "http://localhost:8080/JerseyMessaging/webapi/messagesJson",
data: { get_param: 'author' },
dataType:'json',
success: function (data) {
$(data).each(function(i){
alert(data[i].author);
});
}
});
Another Way
$.getJSON("http://localhost:8080/JerseyMessaging/webapi/messagesJson", function (data) {
$(data).each(function(i){
alert(data[i].author);
});
});
POST METHOD
$.ajax({
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
type: "POST",
//the url where you want to sent the userName and password to
url: 'http://localhost:8080/JerseyMessaging/webapi/messagesJson',
dataType: 'json',
//json object to sent to the authentication url
data: JSON.stringify({
"author": "ulhasid7",
"date": "2016-11-20T21:08:39.671-05:00"
}),
success: function () {
alert("Thanks!");
}
});*/
});
</script>
</head>
<body>
<div id="displayData"></div>
</body>
</html>