Login   Register  
Icontem

File: xpAjaxExample.html

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ricardo Luiz Rossi  >  JavaScript AJAX request  >  xpAjaxExample.html  >  Download  
File: xpAjaxExample.html
Role: Example script
Content type: text/plain
Description: xpAJAX Client
Class: JavaScript AJAX request
Send AJAX requests to a given Web server
Author: By
Last change:
Date: 2013-02-22 19:51
Size: 2,383 bytes
 

Contents

Class file image Download
<html>
	<head>
		<title>xpAjax example</title>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<script type="text/javascript" src="http://classes.rlrossi.com/lib/js/prototypes.js"></script>
		<script type="text/javascript" src="http://classes.rlrossi.com/js/xpajax/xpAjax.js"></script>
		<script type="text/javascript">
			var ajax = new xpAjax("http://classes.rlrossi.com/js/xpajax");

			/* Adds 'replaceAll' Method to Strings Javascript Platform */
			if(typeof(String.prototype.replaceAll) === "undefined")
			  { String.prototype.replaceAll = function(search,replacement)
				  { var newString = this;
					while(newString.indexOf(search) > -1)
					  { newString = newString.replace(search,replacement);
					  }
					return newString;
				  };
			  }

			function getAddress(zip)
			  { ajax.send("xpAjaxexample.php","getAddressResult","{'sourceparms':'"+ajax._uservalues+"','zipcode':21511290}");
			  }

			function getAddressResult(result)
			  { if(result.error)
				  { alert(result.msg + (result.src ? ("\n"+result.src) : ""));
					return;
				  }

				document.getElementById("caption").innerHTML	  = result.caption;
				document.getElementById("zip").innerHTML		  = "ZIP CODE:    &nbsp;"+ result.zip;
				document.getElementById("address").innerHTML	  = "Address:     &nbsp;"+ result.address;
				document.getElementById("neighborhood").innerHTML = "Neighborhood:&nbsp;"+ result.neighborhood;
				document.getElementById("city").innerHTML		  = "City:        &nbsp;"+ result.city;
				document.getElementById("state").innerHTML		  = "State:       &nbsp;"+ result.state;
				document.getElementById("country").innerHTML	  = "Country:     &nbsp;"+ result.country;
						
				return;
			  }
		</script>
	</head>
	<body onload="document.getElementById('zip').readOnly=true;">
		<div style="position:absolute;top:25px;left:50px">
			<form id="testajax" method="post" action="#">
				<p>Get the address for <input type="text" id="zipcode" value="10019" size="5">, NY, USA
					<input type="button" id="GetTheAdress" value="Show me the address" onClick="getAddress(10019);" />
				</p>
			</form>
			<p id="caption"></p>
			<p id="zip"></p>
			<p id="address"></p>
			<p id="neighborhood"></p>
			<p id="city"></p>
			<p id="state"></p>
			<p id="country"></p>
		</div>
	</body>
</html>