HTML and CSS Reference
In-Depth Information
EXAMPLE 18.18 ( CONTINUED )
3. After the eval() evaluates the string returned from the server, it
is converted into an array and displayed below:
Steps for Using Ajax and a JSON Object
EXAMPLE 18.19
1. The JSON text file, " person.json " contains an object literal:
{ "Name": "Joe Shmoe",
"Salary": 100000.50,
"Age": 35,
"Married": true
}
-----------------------------------------------------------------
2. The Ajax program requests the file and evals the response:
// Segment from the Ajax program
function getXMLContents(httpRequest) {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
var person = eval('('+httpRequest.responseText +')') ;
var name=person.Name;
var salary=person.Salary;
var age=person.Age;
var married=person.Married;
alert("Name: "+name +
"\nSalary: " + salary +
"\nAge: " + age +
"\nMarried: "+ married
);
}
else {
alert('There was a problem with the request.');
}
}
}
-------------------------------------------------------------
Search WWH ::




Custom Search