-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpa2.js
89 lines (83 loc) · 2.78 KB
/
pa2.js
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
/*
Scott Kinder
JQuery PA2 Search
*/
"use strict";
(function () {
$(document).ready(function () {
$("#queryarea").keyup(function (e) {
fetchResults();
$.fn.fetchTable();
$.fn.fetchPlayer();
});
});
//Fetches the results and places them in the DOM
function fetchResults() {
var query = $("#queryarea").val();
$.ajax({
type: "POST",
url: "WebService2.asmx/searchTrie",
data: "{ 'search': '" + query + "'}",
contentType: "application/json; charset=utf-8",
success: function (msg) {
$.each(msg, function (key, val) {
for (var i = 0; i < 10; i++) {
//if there is a search result
if (val[i]) {
$("#" + i).css("display", "initial");
$("#" + i).text(val[i]);
} else {
$("#" + i).css("display", "none");
}
}
});
},
error: function (msg) {
alert("fail");
}
});
}
//Fetches the results and places them in the DOM
$.fn.fetchTable = function () {
var query = $("#queryarea").val();
$.ajax({
type: "POST",
url: "WebService2.asmx/searchTable",
data: "{ 'search': '" + query + "'}",
contentType: "application/json; charset=utf-8",
success: function (msg) {
$.each(msg, function (key, val) {
var i = 1;
$.each(val, function (key, val) {
$("#s" + i + " > a").text(val["Title"]);
$("#s" + i + " > a").attr("href", decodeURIComponent(val["Key"]));
$("#s" + i + " > h5").text(decodeURIComponent(val["Key"]));
$("#s" + i + " > h6").text(val["Date"]);
i++;
});
});
},
error: function (msg) {
alert("fail");
}
});
};
$.fn.fetchPlayer = function () {
var query = $("#queryarea").val();
$.ajax({
url: 'http://52.11.96.255/PA1/searchajax.php',
type: 'post',
data: { "playername": query },
success: function (data) {
if (data.toLowerCase().indexOf(query.toLowerCase()) >= 0) {
$("#playerarea").html(data);
} else {
$("#playerarea").empty();
}
},
error: function (error) {
alert('something is wrong' + error);
}
});
};
})();