For example, the following Array, catalogIds,
may be created from a string that consists of Catalog Ids delimited by
whitespace using the $w() function.
var catalogIds=$w(???catalog1 catalog2 catalog3???);
The catalogIds array may be represented as follows.
[???catalog1??™, ???catalog2??™, ???catalog3??™]
3.2.7 Try.these function()
The Try.these()function tries a sequence of functions until one of the
function runs. For example, different browsers create an
XMLHttpRequest differently. Try.these() function may be used to
create an XMLHttpRequest object as shown in following listing.
function getXMLHttpRequest(){
return Try.these(
function() {return new XMLHttpRequest();},
function() {
return new ActiveXObject(???Microsoft.XMLHTTP???);}
);}
3.2.8 Ajax.Request Class
The Prototype library provides the Ajax.Request class to send an
XMLHttpRequest request. The The Ajax.Request constructor may
be used to create an Ajax.Request object.
Ajax.Request ajaxRequest=new
Ajax.Request(url,options);
The options value may be specified with a JavaScript Object
Notation (JSON). For example, an Ajax.Request object may be
created that sends an XMLHttpRequest to a servlet url, which includes
a userid parameter.
var userid=$F('userid');
var url = 'servletURL';
var pars = 'userid=' + userid;
var myAjax = new Ajax.Request(
url, {method: 'get',
parameters: pars, onComplete: showResponse});
48 3 Less JavaScript with Prototype
The url specifies the servlet url to which the request is sent.
Pages:
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63