April 12, 2007

Response to Mike's blog: In need of Javascript assistance

Mike,
Reading your blog post, I did not quite understand what your problems were in parsing the xml. But, I am posting a small chunk of code that I used to parse my xml file. May be you can make use of this.

Basically, it strips off the Title elements from the xml (rerturned by your ISBN call) and creates an element node to display it in the HTML page. You can repeat this process for other elements that you have. Note that the DOM methods are case sensitive. So, double check the tag names you pass to these methods. Hope this helps.

// NOTE : you should have a div with an id resultArea in your html file
var resultTree = document.getElementById('resultArea');

// retrieve the title element
var titles=xmlDoc.getElementsByTagName('Title');
var title = titles[o].childNodes[0].nodeValue;

// create an element node
tempElementNode = document.createElement("h4");

// createa text node with the value extracted from title element
tempTextNode = document.createTextNode("Title : " + title);

// add the text node to the element node previously created
tempElementNode.appendChild(tempTextNode);

// add the resulting element to the result area ..so that
// the title is displayed in the screen
// NOTE : you should have a div with an id resultArea in your html file
resultTree.appendChild(tempElementNode);

Response to Mike's blog: In need of Javascript assistance

Mike,
Reading your blog post, I did not quite understand what your problems were in parsing the xml. But, I am posting a small chunk of code that I used to parse my xml file. May be you can make use of this.

Basically, it strips off the Title elements from the xml (rerturned by your ISBN call) and creates an element node to display it in the HTML page. You can repeat this process for other elements that you have. Note that the DOM methods are case sensitive. So, double check the tag names you pass to these methods. Hope this helps.

// NOTE : you should have a div with an id resultArea in your html file
var resultTree = document.getElementById('resultArea');

// retrieve the title element
var titles=xmlDoc.getElementsByTagName('Title');
var title = titles[o].childNodes[0].nodeValue;

// create an element node
tempElementNode = document.createElement("h4");

// createa text node with the value extracted from title element
tempTextNode = document.createTextNode("Title : " + title);

// add the text node to the element node previously created
tempElementNode.appendChild(tempTextNode);

// add the resulting element to the result area ..so that
// the title is displayed in the screen
// NOTE : you should have a div with an id resultArea in your html file
resultTree.appendChild(tempElementNode);

April 5, 2007

Page not found error in MCubed

Matthew,
I was trying your new layout updates to MCubed, but getting page cannot be found error for all the links at the top, except for the search. Can you please fix it and post it again ?

Response to Andre: DOM problem in IE 6.0

Andre, I took the code you had and dropped it in to a function and it worked perfectly in IE. I even tried changing the width and height, which worked as well. Two things I had to change to make it work locally are ...setting the value of the image attribute and have some div inside the body with some content (div without content does not work ..because you are accessing the firstChild attribute) .....that set aside, not sure what your image variable has.....can you post little more code ?

//creating new image node
var new_pic = document.createElement("img");
//creating new attribute nodes
var height = document.createAttribute("height");
var width = document.createAttribute("width");
var src = document.createAttribute("src");
//Define values for attribute nodes
height.nodeValue = "500";
width.nodeValue = "500";
//image contains link to the picture
//src.nodeValue = image;
src.nodeValue = "code.JPG";
//assigning attribute nodes to the image node
new_pic.setAttributeNode(src);
new_pic.setAttributeNode(width);
new_pic.setAttributeNode(height);
//replacing old node in HTML
document.getElementById("artwork").replaceChild(new_pic, document.getElementById("artwork").firstChild);

April 2, 2007

Response to Tom's comments

Tom,
I read the comment (repeated below) you wrote about my earlier response.

Thanks Chidambaram! The problem is that no session is attached to the logout.php. You could even call the logout PHP without being logged in-- How should Facebook know that it comes from you when the call originates from the server and not from your browser... And we somehow need to tell Facebook that we are logged out... If you only invalidate the session object on the client side this will not be enough?

If you call facebook's logout php it'll get the session information from the request object that you are implicitly sending (by posting to their logout page) and facebook invalidates the session as part of the logout process.

In general, a logout process will never require a userid / username. All that server cares about is the session. Even if you want to persist some user data to the database or something ...you get the user info from the session...and not as a parameter. Try this ...open your browser and login to facebook....open another browser and again login to facebook. These are two different sessions. Even if you logoff from one of these, the other will still function. That means regardless of who the logged in user is, the facebook server just kills the session tied to that browser and nothing more.

You still need to invalidate your MYB session in your PHP (not in your client) after calling facebook's logout page

Response to Aparna's post

From what I know and what I found from googling this ...you are right about Microsoft.XMLHTTP being the "generic" version and Msxml2.XMLHTTP being the version specific version. They refer to different versions of xml parsers installed in the client. It seems, the suggestion is to use Msxml2 and also in IE7 you can use Window.XMLHttpRequest which creates the request in a version independent manner.

You can read the discussion in the msdn blog for more insight.


Response to MapYourBuddies - And the big logout challenge !!

Joern,
I believe there is a problem with the code you posted in your blog (alternate solution to the logout issues you are having)

The doit() function is in the wrong place. It should be in the logout.html file ...since logout.html cannot access the doit() function (which is in the parent window) its not closing the popup. Infact, you don't need doit() funcition at all. There is a onSubmit event handler that you can use.

Add the following handler to the logout.html file (in the form element tag) and update us if you see a change.

onSubmit="setTimeout('window.close()',2000)"

Hope this helps !!

April 1, 2007

Response to MYB - Logout procedures and its problems

Tom, I read the blog you posted initially about the logout problems you guys have. Here are my comments about what you said in your blog. This is only my theory ..I never tried this myself though.

After some Googling for simulating a POST with PHP it still didn’t work. Why? How would Facebook know which user clicked to log out if the request for it comes from a people.emich.edu server? There is no user variable which can be attached to the logout string

I still think simulating a POST (to facebook logout page) within your PHP should work. Because you are creating the facebook session within your MYB session, facebook session is implicitly "owned" by MYB session. Every request you make to facebook after a "login" is in the context of this session.

In general, when a user logs out...the session is invalidated and cannot be used anymore. There is no user variable attached to logout requests because, a session is always tied to one and only one user.

How would Facebook know which user clicked to log out if the request for it comes from a people.emich.edu server? There is no user variable which can be attached to the logout string. Suppose 10 people are logged in simultaneously at MapYourBuddies and one wants to log out; how can Facebook perform the logout from the server side without any reference to the user?

If 10 users are logged in to MYB ...there are 10 MYB session holding a reference to 1 facebook session each (remember ?..you woud've called facebook login 10 times). So, your MYB sessions are always mapped 1 to 1 with facebook session. Since facebook uses session_cookies (mentioned in their privacy policy) to keep track of the session, you don't have to differentiate between the users when posting to facebook logout page. All they need to know is ..the session to invalidate.

March 30, 2007

Response to Srikanth's comment, while reviewing MapYourBuddies

Srikanth,
You mentioned the following 2 things in your review of MapYourBuddies. While I can't speak for that group, here is my insights on why this might be the case. Here are the 2 comments you made.

1. Once login if i refresh the page,it doesnot loads the page.i.e refresh doesnot work

The login process in MYB creates a session in facebook (after you type in the password) and returns a token, which inturn is used to retrieve the session key. While a session key can be used for subsequent requests (within the same session), the token can be used only once. This is one of the general concept in a web application. When a page is refreshed using F5 or refresh button, we are re-submiting the same information to the server again. If you notice the URL parameter (in MYB), the token is being submitted to the PHP again and it gives a invalid parameter message

http://people.emich.edu/jwendelk/MapYourBuddies/I2/main.php?auth_token=b55f3cd7671d5220a75c4645a93c5b4b

If you remove the auth_token parameter and hit enter, you'll be getting the main page again and then you can choose Start MayYourBuddies button ....it'll not ask you for login credentials again (because the session still exists) ....which is the expected behaviour. Hope this helps.

MYB team ....You can prevent this error by checking for the auth_token parameter in the incoming request (in your php) and either redirect the user to your home page automatically or pull values from facebook using the session key previously created (skip the login stuff) ...Just a thought.

2. Once i exit from my login still it continues to be on my login if i press back option

When you use back button, browsers are not always required to send the previous request back to the server (some browsers differ though). In this case, I suspect, the page you are seeing is coming from your browser cache. MYB team, I am not sure whether you are invalidating the session when the user logs out.... Its always a good idea to use session_destroy() in your php when user logs out. This will clear the session and also free-up your server memory !!

Sorry if I am stepping on your turf !!! And Sorry for the long post folks !!! :-))

March 29, 2007

Response to Rosie

Rosie,
Its hard to debug the issue you are having from the code you posted.

My suggestion is, not to do a trial and error method to make a code work or fix a bug (especially true with javascript). You may be lucky one in 10 times, but the rest 9 times you'll end up spending hours debugging your issue and may introduce bugs along the way.Take a clean slate approach and have only the minimum lines of code you need.

You don't need that for-loop until you need to process every occurance of that description, high or low tags. To start with, extract values only from the first occurance (use index 0 in that array you get after you call getElementsByTagName) and make sure it works. Use alerts to pin-point the error. Such a step-by-step approach will keep the focus in the right direction and you also learn along the way

Sorry for not being very specific ....its hard to see few lines of code and tell what the error is. It may not be related to the code you posted at all. Syntactically it appears fine. Post a link in the blog to the xml file you are trying to process. I'll look at it later using firefox.

Archives