Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com�s entire library of video tutorials.
Let's move on beyond setting the feed URL and implement the rest of this setup function. I'm going to do this several times and in several different ways because I want to illustrate to you the various ways in which you can do this and some of the applications for each way of doing it, but for now, let's just get it to work. I have, over here, the code that I tested in JavaScript in HTML document, a blank HTML document that only contains the JavaScript. These are declarations up here and there are only 2 executable lines of code down here in this script. So that's what's running over here and I've tested and it works. So now, we've come over here and we've got to modify the snippet of code that we got from the library. Then I'm going to do a little bit of cleaning up as we're around here just so that the code is a little easier to read. Now, one of the structural differences between the code that I tested over here and this code is that over here, we just set the onload property of XML request to the function we wanted to call. In this code, it's a little bit more structured and the function is placed in a variable and the variable then is used to set the onload property. I'm going to do it this way. So, what I'm going to do is to copy this code, which I used ultimately to set the onload property and I'm going to place it here. I'm going to take out this place holder, which is just a dummy section of code and I'll paste in the code that I was using over here. Now, whenever I paste the code in, it's more than just 1 word or 1 line. I always check to make certain that I haven't skipped a closing or ending bracket. So, notice here, as in many modern editors, if I click on a bracket, I can see its companion bracket and if I've missed something, then it will be incomplete. So, that's a useful way of checking that my paste and the copy was OK. I've got the basics of the code here. This is the feed to fetch. I'm leaving those comments in because it will be useful as we go back through it to see what we've done and this is the function to call when the feed is loaded. I'll take out this part of the comment and move it to the right place. One of the reasons for checking your comments and making certain that they accurately reflect the code is that when you come back to something, you may forget what you've done, and that happens to the best of us, but it seems to be something that can happen more frequently with apps and the reason is, that there is less code to be written in apps. As you've seen, this is really the first time I'm writing code. I've used the user interface in Dashcode to put in reusable objects and to put in templates where I only have to put in 1 word or a URL or something like that and the less code you write, the more unfamiliar it can be when you come back to it and you have to figure out what it is you need to do, which may just be changing one word or 1 URL. So, here is the set of code for the request. This is the code from the snippet that puts the variable into the onload property. We open it. Now, what we're doing here is setting the request header, Cache Control, so that we are not using the cache for this particular request. As the documentation points out, if you wind up using the cache, there are circumstances under which you can get the data that is not the latest data if you are changing it. So let's disable the cache for this request and get the latest data and then I'm coming down here. We'll send it, then I come down here to the very end and check, Yes I Have Matching Brackets. So, this is the basic code and there's only one thing that's missing from it. This function here will set up and it seems to have the code that I used over here because I pasted it in. The bulk of the code actually is the URL and the onload handler, and the onload handler parses what I've received and puts the alert up so I could see what I've gotten. Now, I am declaring an XML doc. So let me move that up here to the setup code and in fact, I'm going to move it up here to the top, and I'm going to move the declaration of XML request up here as well. So it's a more familiar structure with the declarations here, setting the feed, setting the handler and then setting up the other attributes of XML request and sending it. The only thing that's missing is name of location and for now, I'm going to call it from the load handler. So, that's the basics of it and now let's see what we have when we try it.
| Course: | Developing iPhone Web Apps |
| Author: | Jesse Feiler |
| SKU: | 34075 |
| ISBN: | 1-935320-89-0 |
| Release Date: | 2009-12-31 |
| Duration: | 8 hrs / 103 lessons |
| Work Files: |
Yes |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |