Datasheet

Schwartz c01.tex V3 - 12/26/2008 11:38am Page 19
Chapter 1: Social Computing
<script type
=
"text/javascript" language
=
"javascript" src
=
"/
_layouts/1033/search.js?rev
=
yqBjpvg%2Foi3KG5XVf%2FStmA%3D%3D" defer></script>
<script type
=
"text/javascript" language
=
"javascript" src
=
"/
_layouts/1033/EditingMenu.js?rev
=
O4%2BTJbLGM9Af07theU%2BW6A%3D%3D"></script>
The second way is to add the JavaScript code directly to the page it needs to run on. Generally, when a
developer does this, he or she will either create a function that can run later or make a call to a function
or code that will run as it is parsed in-line. For example, the code below will create a variable, run some
logic code with an
if
statement, and create a function or programmatic subroutine that can be called at a
later time.
<script type
=
"text/javascript">
//<![CDATA[
var theForm
=
document.forms[’aspnetForm’];
if (!theForm) {
theForm
=
document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() !
=
false)) {
theForm.__EVENTTARGET.value
=
eventTarget;
theForm.__EVENTARGUMENT.value
=
eventArgument;
theForm.submit();
}
}
//]]>
</script>
<script src
=
"/WebResource.axd?d
=
Ueyb-Jxh5PeDBqOXKfnVlQ2&t
=
633326287538634355"
type
=
"text/javascript"></script>
<script> var MSOWebPartPageFormName
=
’aspnetForm’;</script>
All of the variables that are created outside of a function call are global and can be used in the functions
on the page or linked scripts. The easiest way to view a page to see the JavaScript and linked files is to
right-click on the page and select View Source. The HTML of the page as well as the JavaScript that is
run will be displayed in the default viewer such as Notepad.
Although JavaScript is available on almost every Internet browser application today, it is not a require-
ment when building a social computing application. In fact, there are times when other technologies or
even a full-page refresh might make an application more usable. When JavaScript makes changes to the
page, it can be challenging to get back to exactly what the user was doing if he or she presses the Back or
Refresh buttons.
AJAX
In order to make an interactive site driven with updates of data, a programming technique called AJAX
was introduced in the mid-2000s. Although there had been different ways of dynamically interacting
with content, AJAX provided a standard way for web developers to make dynamic requests to the server
without having a full-page refresh. In common web programming, the Internet browser being used
makes a call to the web server using the Hypertext Transfer Protocol (HTTP). The common model for
HTTP is to make a call and return the HTTP page markup. If the display of the page needs to be modified,
19