- Create a new XMLHttpRequest object (the core of an Ajax application):
<script language= "javascript" type= "Text/javascript" > var xmlHttp = new XMLHttpRequest ();</script>
- Capturing and setting field values with JavaScript code
Gets the form field with the ID value first_name var name = document.getElementById (' first_name '). value;//Modify the value of the form field with the ID value test document.getelemen Tbyid (' Test '). Value = Response[0];
- Create a XMLHttpRequest object on a Microsoft browser
var xmlHttp = false;try { xmlHttp = new ActiveXObject ("Msxml2.xmlhttp");} catch (e) { try { xmlHttp = new Acti Vexobject ("Microsoft.XMLHTTP"); } catch (E2) { xmlHttp = false; }}
- create XMLHttpRequest objects in a way that supports multiple browsers
/* Create a new XMLHttpRequest object to talk to T He Web server */var xmlHttp = false;/* @cc_on @*//* @if (@_jscript_version >= 5) try {xmlHttp = new ActiveXObject ("Msxml 2.XMLHTTP ");} catch (e) {try {xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP"); } catch (e2) {xmlHttp = false; }} @end @*/if (!xmlhttp && typeof XMLHttpRequest! = ' undefined ') {xmlHttp = new XMLHttpRequest ();}
- Getting started: Sending Ajax requests
function CallServer () { //Get the city and state from the Web Form var city = document.getElementById ("City") . value; var state = document.getElementById ("state"). Value; Build the URL to connect to var url = '/scripts/getzipcode.php?city= ' + Escape (city) + ' &state= ' + Escape (state ); Open a connection to the server xmlhttp.open ("GET", url, true); Setup a function for the server to run when it's done xmlhttp.onreadystatechange = updatepage; Send the request xmlhttp.send (null);}
Ajax: A Web Development technology (asynchronous Javascript + XML)