xHttpRequest Test 1

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

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 Server

This is the PHP file to which the demos make requests.

<?php
if ($_POST['demo'] == '1' || $_GET['demo'] == '1')
{
  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>';
  }
}
else if ($_GET['demo'] == '2')
{
  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>
<?php
}
else // demo 3
{
  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>
<?php
}
?>

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 2, Test 3