xHttpRequest Test 2

This test uses 3 xHttpRequest objects. Test 1 uses one xHttpRequest object.

You can run each demo individually or run them all at once.

Demo 1

This demo uses responseText.

Request

v1

v2

v3

GET

POST

Response

Demo 2

This demo uses responseXML. It uses xWalkTree to easily parse the received XML.

Request

Use random: Yes, No

Response

Demo 3

This demo is just like demo 2 except this one receives XML which is more deeply nested. It doesn't matter how deeply nested the XML is - just specify the nodeNames you're looking for and call xParseXml.

Request

Response

Run All Demos

This runs all 3 demos.

The Demo 1 Server

This is the PHP file to which demo 1 makes its requests.

<?php
if (count($_POST))
{
  echo $_POST['v1'];
  echo $_POST['v2'];
  echo $_POST['v3'];
  echo '<p>' . $_POST['rnd'] . '</p>';
}
else if (count($_GET))
{
  echo $_GET['v1'];
  echo $_GET['v2'];
  echo $_GET['v3'];
  echo '<p>' . $_GET['rnd'] . '</p>';
}
?>

The Demo 2 Server

This is the PHP file to which demo 2 makes its requests.

<?php
header('Content-type: text/xml');
?>
<parent>
  <child>
    <gc1>c1 gc1 - text</gc1>
    <gc2><![CDATA[c1 gc2 - cdata]]></gc2>
  </child>
  <child>
    <gc1>c2 gc1 - text</gc1>
    <gc2><![CDATA[c2 gc2 - cdata]]></gc2>
  </child>
  <child>
    <gc1>c3 gc1 - text</gc1>
    <gc2><![CDATA[c3 gc2 - cdata]]></gc2>
  </child>
  <child>
    <gc1>c4 gc1 - text (<?php echo $_GET['rnd'] ?>)</gc1>
    <gc2><![CDATA[c4 gc2 - cdata (<?php echo rand() ?>)]]></gc2>
  </child>
</parent>

The Demo 3 Server

This is the PHP file to which demo 3 makes its requests.

<?php
header('Content-type: text/xml');
?>
<parent>
  <child>
    <gc>
      <ggc1>c1 gc1 ggc1 - text</ggc1>
      <ggc2><![CDATA[c1 gc1 ggc2 - cdata]]></ggc2>
    </gc>
    <gc>
      <ggc1>c1 gc2 ggc1 - text</ggc1>
      <ggc2><![CDATA[c1 gc2 ggc2 - cdata]]></ggc2>
    </gc>
  </child>
  <child>
    <gc>
      <ggc1>c2 gc1 ggc1 - text</ggc1>
      <ggc2><![CDATA[c2 gc1 ggc2 - cdata]]></ggc2>
    </gc>
    <gc>
      <ggc1>c2 gc2 ggc1 - text (<?php echo $_GET['rnd'] ?>)</ggc1>
      <ggc2><![CDATA[c2 gc2 ggc2 - cdata (<?php echo rand() ?>)]]></ggc2>
    </gc>
  </child>
</parent>

What?

Simple experiments with the XMLHttpRequest object.

Source?

View the source and documentation for xHttpRequest.

These demos also make good use of xWalkTree in parsing the returned XML.

More?

Test 1, Test 3