0% found this document useful (0 votes)
4 views1 page

Book Search Functionality Code

This document defines JavaScript functions to query a database for books by title or author and display the results in an HTML table. When the user clicks the title or author query buttons, an AJAX call is made to retrieve book data from the backend and the results are appended as new rows in the table.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Book Search Functionality Code

This document defines JavaScript functions to query a database for books by title or author and display the results in an HTML table. When the user clicks the title or author query buttons, an AJAX call is made to retrieve book data from the backend and the results are appended as new rows in the table.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

$(document).

ready(function() {
2:
$("#btnTitleQuery").bind("click", function() {
3:
$("#query_results").empty();
4:
$("#query_results").append('<table id="ResultsTable"
class="BooksTable"><tr><th>BookNum</th><th>Title</th><th>Author</th></tr>');
5:
$.ajax({
6:
type: "POST",
7:
contentType: "application/json; charset=utf-8",
8:
url: "[Link]/GetBooksByTitle",
9:
data: '{ strTitle: "' + $("#txtTitle").val() + '" }',
10:
dataType: "json",
11:
success: function(msg) {
12:
var c = eval(msg.d);
13:
for (var i in c) {
14:
$("#ResultsTable tr:last").after("<tr><td>" + c[i][0] + "</td><td>" + c[i][1] +
"</td><td>" + c[i][2] + "</td></tr>");
15:
}
16:
}
17:
});
18:
})
19:
$("#btnAuthorQuery").bind("click", function() {
20:
$("#query_results").empty();
21:
$("#query_results").append('<table id="ResultsTable"
class="BooksTable"><tr><th>BookNum</th><th>Title</th><th>Author</th></tr>');
22:
$.ajax({
23:
type: "POST",
24:
contentType: "application/json; charset=utf-8",
25:
url: "[Link]/GetBooksByAuthor",
26:
data: '{ strAuthor: "' + $("#txtAuthor").val() + '" }',
27:
dataType: "json",
28:
success: function(msg) {
29:
var c = eval(msg.d);
30:
for (var i in c) {
31:
$("#ResultsTable tr:last").after("<tr><td>" + c[i][0] + "</td><td>" + c[i][1] +
"</td><td>" + c[i][2] + "</td></tr>");
32:
}
33:
}
34:
});
35:
})
36: });

You might also like