IAM Home
IAM Wiki
Emergent Web Technologies Spring 2009 Class 4
| 38.107.191.86
| Talk for this IP
| Log in
Contents |
Just a little bit more for JavaScript basics this week. Specifically, Object Oriented JavaScript. JavaScript doesn't actually have "classes" per se, but it does have objects and objects can be copied in a way that's similar to the way that classes work in other languages.
Also covered this week: JSON with Padding or JSONP. JSONP is basically a hack to get around the fact that Ajax calls cannot be made across domains. Despite the fact that it's a hack, some sites make use of it for their JavaScript APIs, so it's a helpful trick to know. jQuery wraps up JSONP calls in a function that makes it easy to do.
Finally, I'm introducing the Google Maps API using the Google API Playground. The API playground is a nice way to try out Google's APIs without needing to configure things on your own.
If you're interested in JavaScript (or in finding a web related job), sign up for next week's Chicago JavaScript meetup. It's 6:30 PM, next Thursday. It's free and a great place to meet other people interested in JavaScript and web development. Plus, free pizza!
Build a word counter for textarea tags. This is an activity that demonstrates how you can use object oriented JavaScript to build reusable JavaScript components on your pages.
Adding a new wordcounter should be a simple as this:
new WordCount(textareaNode);
You can copy the template here
The solution for this assignment is here
Use JSONP to send messages to a server and interpret the messages as they come back. I have a page that displays messages from remote clients as they come in.
http://www.mattephraim.com/ewt/class_4/messages/
You can add messages by sending them to the server at
http://www.mattephraim.com/ewt/class_4/messages
The server takes three parameters:
jQuery will handle the jsoncallback function name if you format your url like this:
http://www.example.com/api?jsoncallback=?
Use the jQuery.getJSON function and jQuery will automatically give your anonymous function a name and insert it into the url.
The solution for this assignment is here
Use this geocoder to geocode some of the locations that you picked out for the assignment due on Friday. Then open up the Google Maps API playground. Use the code editor to add some of your points to the map.
Once you've got your points added, copy the code that adds the points and go to the info window example. Copy in the code for adding your points and then add info windows for each point.
I'm not sure what the issue is, but if you sign up for a Google Maps key and use the code that they supply on the key signup page, you will get an error that says the API key is for another site. The map seems to work anyway, so I don't know why the message pops up.
There's another method for including the Google Maps API that is documented here. An example snippet of code is below. If you use that method, you shouldn't get an error.
<script type="text/javascript" src="http://www.google.com/jsapi?key={your_key_here}"></script> <script type='text/javascript'>google.load('maps', '2');</script>
For next week's assignment you'll be extending the information you provided for this week's assignment.
Feel free to email me or schedule a time to meet me at my office if you have questions about this assignment.
Assignment Due: 2/27/2009 10PM