Aaxsys Notes
|
![]() |
Previous page | Next page |
function addRows(fields,tBody) { var row,cell,textNode; row = document.createElement("tr"); cell = document.createElement("td"); txtNode = document.createTextNode(fields[0]); cell.appendChild(txtNode); row.appendChild(cell); cell = document.createElement("td"); txtNode = document.createTextNode(fields[1]); cell.appendChild(txtNode); row.appendChild(cell); cell = document.createElement("td"); txtNode = document.createTextNode(fields[2]); cell.appendChild(txtNode); row.appendChild(cell); cell = document.createElement("td"); txtNode = document.createTextNode(fields[3]); cell.appendChild(txtNode); row.appendChild(cell); cell = document.createElement("td"); tBody.appendChild(row); }
Adding the unit pictures.
In order to add the unit pictures, we insert the following
in the unit loop:
aFields[4] = getTag(Units[i],"PictureLink"); aFields[4] = 'http://www.aaxsys.com' + aFields[4];Then, in addRows we add img = document.createElement("img"); img.src = fields[4]; scaleImage(img,100); cell.appendChild(img); row.appendChild(cell); |
Here, we have scaled the images to a standard size
so that they fit in a square 100 pixels wide. The following function
can be used for this purpose:
function scaleImage(image,iDim) { var h = image.height; var w = image.width; if(h >= w) {image.height = iDim; if (w > 0) { image.width = iDim * (w/h)} else image.width = 0;} else {image.width = iDim; if (h > 0) { image.height = iDim * (h/w)} else image.height = 0;} }
But what about Cross-Domain Security?
Fortunately, there is a natural solution to enable such cross-domain requests. If the url points to your own domain, then Ajax has no problem using the resource. Therefore, if you can provide another script that can make the remote call to Aaxsys on behalf of the Javascript and then return the resulting XML, then the modified example will work as intended. Luckily, this kind of proxy can be provided with a minimum effort. Presumably your website has PHP enabled. You can download a simple PHP script from developer.yahoo.com. In order to work with the above example, two changes are needed: In the script, change the hostname to "www.aaxsys.com". To handle our POST requests, the while loop in the yahoo script should be replaced by a for loop such as if ($_POST['yws_path']) { $postvars = ''; for ($i=0;$i < count($_POST);$i++) { $postvars .= key($_POST).'='.current($_POST).'&'; next($_POST); } } |
Next Page |