I actually got help with this assignment but I am having trouble executing it. I
ID: 3596080 • Letter: I
Question
I actually got help with this assignment but I am having trouble executing it. I NEED HELP!!!!!
Here is the assignment:
Download the Assignment 8 code from GitHub. (Here's the link to get the information mentioned; https://github.com/DonnieSantos/IT-2320/tree/master/Week%208%20-%20Introduction%20to%20AJAX/Assignment%208/Assignment8). The solution is already set up with a front and back end to do most of the work. The back end has a small database of Cleveland Cavaliers players, and if provided with a player number, will respond with the player’s name. The tech specs of the back end are provided and documented in the Requirements folder. The tech specs, along with a screenshot example using the Advanced REST client, clearly demonstrate how to format a JSON request, and receive a JSON response. Your assignment is to use JQuery to capture the player number entered in the textbox on the screen, and when the user clicks the “Get Player Information”, use the JQuery ajax method to retrieve the player’s name upon receiving the response from the server. If the number entered does not exist in the database, you will receive an error message. Either way, you will indicate the player’s name and number, or the error message, in the red output box on the screen. (attached is a copy of the data in the back end database, but you should NOT have to look at any of the C# back end code)
Here is my HTML:
<head>
<title>Cavs Assignment</title>
<link href="~/Styles/Home.css" rel="stylesheet" />
<script language= “javascript” src= “jquery-1.2.6.js”></script>
<script src="~/Scripts/JQuery.js"></script>
<script src="~/Scripts/Home.js"></script>
</head>
<body>
<div class="button1">Get Mock Response, No Data</div>
<div class="button2">Get Message Based On Player Number</div>
<div>Player Number</div>
<input class="Player Number" type="text" />
</body>
Here is My Scripts:
var Home = {}
Home.Button1Click = function ()
{
$.get("Home/GetMockResponseNoData", function (rawResponseData, status)
{
alert(rawResponseData);
var deserializedData = JSON.parse(rawResponseData);
var people = deserializedData.Data;
for (var i = 0; i < people.length; i++)
{
alert(people[i].Name);
alert(people[i].Age);
}
});
}
Home.Button2Click = function ()
{
$.ajax
({
url: "Home/GetResponseBasedOnZIPCode",
data: { Player Name : $(".Player Name").val() },
success: function (result) { alert(result); }
});
}
$(document).ready(function ()
{
$(".button1").click(Home.Button1Click);
$(".button2").click(Home.Button2Click);
});
Here is my CSS:
.button1
{
width: 250px;
border: 1px solid black;
margin: 20px 20px 20px 20px;
}
.button2
{
width: 250px;
border: 1px solid black;
margin: 20px 20px 20px 20px;
}
PLEASE Help.
Explanation / Answer
The following is the code for playerDetails.jsp, which expects player number and returns name of the player in the form of JSON
<% @ page import =”java.sql.*” contentType =”text/ json”%>
<%
String playerNumber = request.getParameter(“PlayerNumber”);
Class.forName(“oracle.jdbc.driver.OracleDriver”);
Connection con= DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:XE”,”hr”,”hr”);
Statement st= con.createStatement();
ResultSet rs= st.executeQuery(“select name from Player where PlayerNumber=”+ playerNumber);
If(rs.next())
{
out.println(“name”);
out.println(“”+rs.getString(1)+””);
}
Else
{
Out.println(“{” error”:”Employee id not found !”}”);
}
rs.close();
st.close();
con.close();
%>
Following is the JQuery Ajax file:
<html>
<head>
<title>AJAX and JSON with JQuery</title>
<script language= “javascript” src= “jquery-1.2.6.js”></script>
<script language= “javascript”>
function getPlayerInformation()
{
$.getJSON(“Player.jsp”, {playerNumber : $(“input:textbox”).val()}, displayResult)
}
function displayResult(data)
{
if(data.error)
{
$(“#playerName”).val(“ ”);
Alert(data.error);
}
Else
{
$(“#playerName”.val(data.name));
}
}
</script>
</head>
<body>
<form id=”form1”>
<h2> Player Information </h2>
<table>
<tr>
<td> PlayerNumber </td>
<td> <input type =”int” id= “playernumber” size=”10”/> <input type=”button” value=”GetPlayerInformation” /></td>
</tr>
<tr>
<td> PlayerName </td>
<td><input type = “text” id=”name” /> </td>
</tr>
</table>
</form>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.