Java Reference
In-Depth Information
var request = new HttpRequest(url, checkEmail_callBack);
request.send();
}
The checkEmail_callBack() function uses the same logic as checkUsername_callBack() , but it is
based on the Email fi eld's value.
function checkEmail_callBack(sResponseText)
{
var emailValue = document.getElementById(“email”).value;
if (sResponseText == “available”)
{
alert(“The email “ + emailValue + “ is currently not in use!”);
}
else
{
alert(“I'm sorry, but “ + emailValue + “ is in use by another user.”);
}
}
Once again, the function checks to see if the server's response is available, and lets the user know
that the e-mail address is currently not being used. If the address is not available, a different message
tells the user his e-mail is not available.
Things to Watch Out For
Using JavaScript to communicate between server and client adds tremendous power to the language's
abilities. However, this power does not come without its share of caveats. The two most important
issues are security and usability.
Security Issues
Security is a hot topic in today's Internet, and as a Web developer you must consider the security restric-
tions placed on Ajax. Knowing the security issues surrounding Ajax can save you development and
debugging time.
The Same-Origin Policy
Since the early days of Netscape Navigator 2.0, JavaScript cannot access scripts or documents from a dif-
ferent origin. This is a security measure that browser makers adhere to; otherwise, malicious coders could
execute code wherever they wanted. The same-origin policy dictates that two pages are of the same origin
only if the protocol (HTTP), port (the default is 80), and host are the same.
Consider the following two pages:
Page 1 is located at
http://www.site.com/folder/mypage1.htm
Page 2 is located at
http://www.site.com/folder10/mypage2.htm
Search WWH ::




Custom Search