FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Ajax quiz -- 25 FRIH$





Aredon
I wrote up this quiz and I have all the answers prepared before-hand and I have prepared before-hand proof to each of the correct answers.

25 FRIH$ to the first person to answer all 10 questions correctly in their post. You may submit multiple entries however only one entry per post and no double-posting. All questions must be answered with either True/False or Yes/No as specified directly-following each question.

1) Ajax stands for Synchronous JavaScript and XML.
(True or False)

2) Ajax is a programming language.
(True or False)

3) Regarding the XMLHttpRequest Object, does the order in which one calls the "open" method and assign a function to the "onreadystatechange" event handler matter?
(Yes or No)

4) Can a call to the "send" method fire an error (assuming the user's browser supports the XMLHttpRequest Object and the "send" method )?
(Yes or No)

5) ActiveX can be disabled via browser settings.
(True or False)

6) The XMLHttpRequest object can be disabled via browser settings.
(True or False)

7) Assuming that "xmlhttp" is a user-defined variable that carrys the Ajax requesting object, xmlhttp.status can carry a value of 4 after a successful request.
(True or False)

8) The XMLHttpRequest object supports a method called "quit".
(True or False)

9) Assuming that "xmlhttp" is a user-defined variable that carrys the Ajax requesting object, xmlhttp.status can carry a value of 0 after a successful request.
(True or False)

10) The XMLHttpRequest object can be used on subdomain1.mysite.com to request a page located at subdomain2.mysite.com according to the specification.
(True or False)
vinx_18
1. False ... it Asynchronous
2. False .. a web development technique
3. no
4. No..sends a request
5. True
6. false
7. false .. 101, 301..etc
8. false .. abort() only
9. false .. 101, 301.. etc
10. false
Aredon
vinx_18 wrote:
1. False ... it Asynchronous
2. False .. a web development technique
3. no
4. No..sends a request
5. True
6. false
7. false .. 101, 301..etc
8. false .. abort() only
9. false .. 101, 301.. etc
10. false

You scored a 60%.
For being the first person to try out the quiz I'll give you 60% of the 25 frih$ which is 15 frih$.
*sends 15 frih$*
(this doesn't deduct from the 25frih$ for the first person to get all 10 correct)
Since you had a try at the quiz now, please give someone else a chance before submitting a new entry.
vinx_18
Thanks buddy.. Can you send to me my wrong answers?
Aredon
vinx_18 wrote:
Thanks buddy.. Can you send to me my wrong answers?

*Dispatches the answers to the questions that vinx_18 got wrong in a PM along with proof and explanation for each of the questions*
(note you are no longer eligible for the 25 FRIH$ of this quiz because you now have the correct answers handy)

When someone gets all 10 correctly in their post,
I will publicize my proof and explanation for each of the questions.
vinx_18
Thanks... You help me a lot. now it adds up in my brain bank...
manumiglani
1 F
2 F
3 y
4 n
5 t
6 f
7 t
8 f
9 t
10 f
TarsajumaClan
1. False
2. False
3. yes
4. No
5. false
6. true
7. false
8. false
9. false
10. true
Consider these answers to by my attempt to christmas tree lol. I have no clue on any of this stuff lol.
Aredon
manumiglani wrote:
1 F
2 F
3 y
4 n
5 t
6 f
7 t
8 f
9 t
10 f

You scored a 70%
TarsajumaClan wrote:
1. False
2. False
3. yes
4. No
5. false
6. true
7. false
8. false
9. false
10. true

You scored a 60%
riv_
1false
2false
3yes
4no
5true
6false
7false
8false
9true
10true

..hmmm I don't know much about ajax yet. This will be good practice for me. Thanks!
MrBlueSky
1. False
2. False
3. Yes
4. Yes
5. True
6. False
7. True
8. False
9. False
10. False
mattneed
1. False
2. False
3. yes
4. No
5. false
6. true
7. false
8. false
9. false
10. true
LukeakaDanish
1) False
2) False
3) No
4) Yes
5) Yes
6) False
7) True
8 ) True
9) False
10) True

Not as easy as I thought it would be Smile

Plz PM me the corrections Smile
Alias
1. False
2. False
3. Yes
4. No
5. True
6. False
7. True
8. False
9. True
10. True

Quite hard for me because I don't have that much knowledge on XML. Though I just give it a try. Smile
fx-trading-education
1 False
2 False
3 Yes
4 No
5 True
6 True
7 True
8 False
9 False
10 True
Blu_Spykz
True
True
No
Yes
True
True
False
False
False
True
Aredon
riv:
70%

MrBlueSky:
70%

mattneed:
60%

LukeakaDanish:
40%
(Your answer to #5 used an invalid enumerator. I treated your "Yes" as a "True".)
I will PM you with the correct answers and an explanation.

Alias:
60%

fx-trading-education:
60%

Blu_Spykz:
50%
Montressor
1. False
2. False
3. Yes
4. Yes
5. False
6. True
7. True
8. False
9. True
10. False
Just some guesses
q20201369
False
False
Yes
Yes
True
True
False
False
False
True
vaoger
1. False
2. True
3. No
4. No
5. True
6. True
7.False
8. False
9.False
10.False
mayank_abhishek
1. FALSE
2. NO
3. YES
4. NO
5. TRUE
6. FALSE
7. FALSE
8. FALSE
9. TRUE
10. FALSE

- Mayank Abhishek
Aredon
Montressor 80%
q20201369 80%
vaoger 60%
mayank_abhishek 80%
mayank_abhishek
1. FALSE
2. NO
3. YES
4. YES
5. TRUE
6. TRUE
7. FALSE
8. FALSE
9. TRUE
10. FALSE

- Mayank Abhishek Rolling Eyes
Aredon
We have a winner, congrats to mayank_abhishek! The 25 frih$ is yours.
Note to the moderators: Please keep this thread open so others can reply to my proofs and also because I am thinking of creating another quiz because it flowed so well.

As promised, here are the answers to each of the quesions along with the proofs:

Before testing some of the codes listed in this post, you may need to first obtain this file:

xmlhttp_emulator.js
Code:

//////////////////////////////////////////////////////////////////////////////////////
//                                                                                  //
// header("Description: Cross-browser XMLHTTP Request Object support");             //
// header("Author: Ultimater at gmail dot com");                                    //
// header("Last-Modified: Tue, 09 Jan 2007 22:38:17 PST");                          //
//                                                                                  //
//////////////////////////////////////////////////////////////////////////////////////
 

if(typeof xmlhttp=="undefined")var xmlhttp=false;

/* running locally on IE6,IE7 */                      ;/*Gotta love IE's support for Conditional Compilation*/; /*@cc_on
  if(location.protocol=="file:"){
   if(!xmlhttp)try{ xmlhttp=new ActiveXObject("MSXML2.XMLHTTP"); }catch(e){xmlhttp=false;}
   if(!xmlhttp)try{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){xmlhttp=false;}
  }                                                                                                             @cc_off @*/

/* IE7, Firefox, Safari, Konqueror, Opera... the conventional/standard way */
//Yes, standard: http://www.w3.org/TR/XMLHttpRequest/
  if(!xmlhttp)try{ xmlhttp=new XMLHttpRequest(); }catch(e){xmlhttp=false;}

/* IE5, IE6 */
  if(typeof ActiveXObject != "undefined"){
   if(!xmlhttp)try{ xmlhttp=new ActiveXObject("MSXML2.XMLHTTP"); }catch(e){xmlhttp=false;}
   if(!xmlhttp)try{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){xmlhttp=false;}
  }

/* IceBrowser */
  if(!xmlhttp)try{ xmlhttp=createRequest(); }catch(e){xmlhttp=false;}
// Note IceBrowser does not support responseXML

//////////////////////////////////////////////////////////////////////////////////////
//                                                                                  //
//                                   NOTE                                           //
//                                                                                  //
//       As of version 7.0, IE offers support for the native XMLHttpRequest         //
// object, but the way IE implemented the native object is limited to the web.      //
// i.e. it prohibits xmlhttp requests to the "file:" protocol while other           //
// browsers such as Firefox permit it.  ALTHOUGH IE'S IMPLEMENTATION IS             //
// SUFFICIENT FOR THE WEB, when the webpage is in the development stage the         //
// "file:" protocol is used.  For this reason, IE is served with ActiveX if off     //
// the web otherwise if it is on the web, then IE is served with the native         //
// object.  However IE6.0 doesn't support the native XMLHttpRequest object and      //
// will be served with ActiveX both on the web and off the web alike.  The          //
// approach this script uses to determine if the script is off the web is:          //
// if(location.protocol=="file:")                                                   //
//                                                                                  //
//////////////////////////////////////////////////////////////////////////////////////

I've seen the logic of many other similar cross-browser attempts to create the request and mine is so far the best. The runner-up from the many I've seen is http://jibbering.com/2002/4/httprequest.html however it first checks for ActiveX to be enabled and serves IE7 users with ActiveX when it could be serving them with the native XMLHttpRequest object. It still handles the same browsers my script handles however IE shouldn't need to resort to ActiveX if it supports the native object, although an exception to the "file" protocol where ActiveX is to be used.


1) Ajax stands for Synchronous JavaScript and XML.
False, AJAX is an acronym for Asynchronous JavaScript And XML. The XMLHttpRequest object does, however, allow synchronous requests.
http://www.w3schools.com/ajax/ajax_intro.asp

2) Ajax is a programming language.
False, AJAX is a technique not a programming language. More specifically it is a programming technique that is used on the web.
http://www.w3schools.com/ajax/ajax_intro.asp
Note that "AJAX is not a new programming language" doesn't imply that it is an old programming language but rather Ajax is "new" to the person learning it however Ajax isn't a programming language at all.

3) Regarding the XMLHttpRequest Object, does the order in which one calls the "open" method and assign a function to the "onreadystatechange" event handler matter?
Yes, the order does matter and it is best to call the open method before assigning functions to the onreadystate event hander.

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="content-script-type" content="text/javascript">
<title>&nbsp; open before onreadystatechange</title>

<!-- don't forget to obtain a copy -->
<script type="text/javascript" src="xmlhttp_emulator.js"></script>

</head>
<body>
<script type="text/javascript">
var ld=function(){
//alert("readyState:"+xmlhttp.readyState+" status:"+xmlhttp.status)
if(xmlhttp.readyState!=4)return;
alert(xmlhttp.responseText)
}

function newRequest(){
xmlhttp.onreadystatechange=ld;
xmlhttp.open("GET","#",true);
xmlhttp.send(null);
}

</script>
<p><input type="button" onclick="newRequest()" value="request"></p>
</body>
</html>

Run the above in IE (either offline or online. I called it "t1.htm") and you should be able to click the "request" button once and get an alert with the responseText as expected.
However if you try to click the button again, you will receive no more alerts. Now edit the newRequest function and re-order the open and onreadystate lines and IE should now be able to preform the request as many times as you click the button. One can also get around this by overriding the xmlhttp variable with a new object, although very unprofessional. Also note that the onreadystatechange event handler if called as a result of calling open. As a result of placing onreadystatechange prior to open, it will call the event handler an additional time.


4) Can a call to the "send" method fire an error (assuming the user's browser supports the XMLHttpRequest Object and the "send" method )?
Yes, behold the "send" method is error prone locally (when no server is involved) and the file is not found.
Give this a run locally ("file" protocol):
Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="content-script-type" content="text/javascript">
<title>&nbsp; send method is error prone</title>

<!-- don't forget to obtain a copy -->
<script type="text/javascript" src="xmlhttp_emulator.js"></script>

</head>
<body>
<script type="text/javascript">
var myFile="file_does_not_exist.htm";

xmlhttp.open("GET",myFile,true);
xmlhttp.onreadystatechange=function(){
alert("readyState:"+xmlhttp.readyState+" status:"+xmlhttp.status)
}
try{
xmlhttp.send(null);
}catch(e){
alert("The \"send\" method has involked an error!")
}
</script>
</body>
</html>

The send method is also error prone in Firefox if you don't send it an argument because it requires an argument makes sure it gets one or it will complain. Also in Firefox the alert method causes an error if it doesn't get an argument.

5) ActiveX can be disabled via browser settings.
True, http://www.cyberanswers.org/index.php?page=java

6) The XMLHttpRequest object can be disabled via browser settings.
True, Internet Explorer 7, by default, comes with support for the native
XMLHttpRequest object hence the code alert(window.XMLHttpRequest) will alert [object]
But it can also be disabled in IE7:
http://i42.photobucket.com/albums/e317/Ultimater/screenshots/Enable_native_XMLHTTP_support.png
hence alert(window.XMLHttpRequest) will alert undefined.

7) Assuming that "xmlhttp" is a user-defined variable that carrys the Ajax requesting object, xmlhttp.status can carry a value of 4 after a successful request.
False, xmlhttp.status won't carry a value of 4 after a successful request but rather 200 for "Ok".
Also anything between 200 and 300 is a successful request.
304 is for 'Not Modified' meaning the page was not modified and the browser should use the cached version. This is still a successful request.
Also if xmlhttp.status has a value of 0 or has a boolean value of false i.e. it is undefined or null etc, then it could also be a successful request.
This was a harder question because xmlhttp.readyState will equal 4 when ready and xmlhttp.status will carry a value of 200 after a successful request online.
1xx: Information
2xx: Successful
3xx: Redirection
4xx: Client Error
5xx: Server Error
However the standard status values are ment for server to client communication. If there is no server involved (running locally), even if the request fails, a succesful request will never hold a value of 200 but rather 0. Run this locally:

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="content-script-type" content="text/javascript">
<title>&nbsp; xmlhttp.status:0 for success</title>

<!-- don't forget to obtain a copy -->
<script type="text/javascript" src="xmlhttp_emulator.js"></script>

</head>
<body>
<script type="text/javascript">
xmlhttp.open("GET","#",true);
xmlhttp.onreadystatechange=function(){
alert("readyState:"+xmlhttp.readyState+" status:"+xmlhttp.status)
}
xmlhttp.send(null);
</script>
</body>
</html>


8) The XMLHttpRequest object supports a method called "quit".
False, the XMLHttpRequest object does NOT support a method called "quit" however it does support a method called "abort".
Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="content-script-type" content="text/javascript">
<title>&nbsp; abort and quit</title>

<!-- don't forget to obtain a copy -->
<script type="text/javascript" src="xmlhttp_emulator.js"></script>

</head>
<body>
<script type="text/javascript">
alert("The method xmlhttp.quit is a method: "+("quit" in xmlhttp))//false
alert("The method xmlhttp.abort is a method: "+("abort" in xmlhttp))//true
</script>
</body>
</html>


9) Assuming that "xmlhttp" is a user-defined variable that carrys the Ajax requesting object, xmlhttp.status can carry a value of 0 after a successful request.
True, xmlhttp.status can indeed carry a value of 0 after a successful request see #7.

10) The XMLHttpRequest object can be used on subdomain1.mysite.com to request a page located at subdomain2.mysite.com according to the specification.
False. http://www.w3.org/TR/XMLHttpRequest/
Quote:

When a non same-origin url argument is given user agents should throw a SECURITY_ERR exception.
mayank_abhishek
Hey!

I won! I won!@!

This is great!! Exclamation Very Happy Exclamation Idea
Related topics
Reply to topic    Frihost Forum Index -> Miscellaneous -> Contests

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.