AJAX - The Complete Reference

(avery) #1

26 Part I: Core Ideas


/* fix the omissions */
encodedVal = encodedVal.replace(/~/g,"%7E");
encodedVal = encodedVal.replace(/!/g,"%21");
encodedVal = encodedVal.replace(/\(/g,"%28");
encodedVal = encodedVal.replace(/\)/g,"%29");
encodedVal = encodedVal.replace(/'/g,"%27");
}
/* clean up the spaces and return */
return encodedVal.replace(/\%20/g, "+");
}

Since this is quite a bit different from the other modifications of the rating example, the
complete code for using iframes with POST is presented here for inspection. It can also be
found at http://ajaxref.com/ch2/onewayiframepost.html. A screen capture that reveals
what is happening behind the scenes in the example is shown in Figure 2-3.

<!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=iso-8859-1" />
<title>Chapter 2 : Iframe Rating - POST - One Way</title>
<script type="text/javascript">
function encodeValue(val)
{
var encodedVal;
if (!encodeURIComponent)
{
encodedVal = escape(val);
/* fix the omissions */
encodedVal = encodedVal.replace(/@/g,"%40");
encodedVal = encodedVal.replace(/\//g,"%2F");
encodedVal = encodedVal.replace(/\+/g,"%2B");
}
else
{
encodedVal = encodeURIComponent(val);
/* fix the omissions */
encodedVal = encodedVal.replace(/~/g,"%7E");
encodedVal = encodedVal.replace(/!/g,"%21");
encodedVal = encodedVal.replace(/\(/g,"%28");
encodedVal = encodedVal.replace(/\)/g,"%29");
encodedVal = encodedVal.replace(/'/g,"%27");
}
/* clean up the spaces and return */
return encodedVal.replace(/\%20/g,"+");
}
function sendRequest(url, payload)
{

function makeIframe()
{
if (window.ActiveXObject)
var iframe = document.createElement("<iframe />");
Free download pdf