Find file
Fetching contributors…
Cannot retrieve contributors at this time
80 lines (60 sloc) 1.64 KB
Lecture 7 - CSC 210 Fall 2015
Philip Guo
<title>Web 2.0 demo</title>
<script src=""></script>
<script type="text/javascript">
$(document).ready(function() {
console.log("Hello world!");
$("#lookupButton").click(function() {
var nameToLookup = $("#nameBox").val();
// From:
// Using the core $.ajax() method
// The URL for the request
url: "cgi-bin/",
// The data to send (will be converted to a query string)
data: {
requested_name: nameToLookup
// Whether this is a POST or GET request
type: "GET",
// The type of data we expect back
//dataType : "text",
dataType : "json",
// Code to run if the request succeeds;
// the response is passed to the function
success: function( data ) {
console.log("You received some data!");
$("#nameDiv").html("My name is " + data.myName);
$("#ageDiv").html("My age is " + data.myAge);
$("#profileImage").attr("src", data.myImage);
// Code to run if the request fails
error: function() {
alert( "Sorry, there was a problem!" );
Name: <input id="nameBox" type="text" size="30"/>
<button id="lookupButton">Get profile</button>
<div id="nameDiv">Your Name</div>
<div id="ageDiv">Your Age</div>
<img id="profileImage" src="truck.jpg" style="width: 300px;"/>