By default, Spry data sets use the HTTP GET method to retrieve XML data. The data set can also retrieve data using the HTTP POST method, by specifying additional constructor options, as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Dynamic Region Example</title> <script type="text/javascript" src="../../includes/xpath.js"></script> <script type="text/javascript" src="../../includes/SpryData.js"></script> <script type="text/javascript"> var dsPhotos = new Spry.Data.XMLDataSet("/photos.php", "/gallery/photos/photo", { method: "POST", postData: "galleryid=2000&offset=20&limit=10", headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" } }); </script> </head> . . . <body> </body> </html>
If you use the POST method, but don’t specify a content type, the default content type is set to "application/x-www-form-urlencoded; charset=UTF-8".
The following table shows the HTTP-related constructor options that you can specify.
Option |
Description |
---|---|
method |
The HTTP method to use when fetching the XML data. Must be the string "GET" or "POST". |
postData |
Can be a string containing URL encode form arguments or any value supported by the XMLHttpRequest object. If a "Content-Type" header is not specified in conjunction with the postData option, the "application/x-www-form-urlencoded; charset=UTF-8" content type is used. |
username |
The server username to use when accessing the XML data. |
password |
The password to use in conjunction with username when accessing the XML data. |
headers |
An object or associative array that uses the HTTP request field name as its property and key to store values. |