Results 1 to 2 of 2

Thread: Parsing out div content from XMLHttpRequest

  1. #1
    Join Date
    Jul 2011

    Parsing out div content from XMLHttpRequest

    I am trying to use XMLHttpRequest() to call a php file which queries a database and returns a row of data separating each column by a semicolon.

    Here is the JavaScript that I am using:

    PHP Code:
    if (window.XMLHttpRequest)
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

                if (
    xmlhttp.readyState==&& xmlhttp.status==200)
    var data xmlhttp.responseText;
    selectionData data.split(";");                
    xmlhttp.open("GET","householdinfoquery?fam=" FAMTYPE "&year=" YEAR "&subgeo=" OECD,true);
    This code calls the "householdinfoquery" page. Since this site is built on drupal, the householdinfoquery is a page node containing the following PHP code:

    PHP Code:
    $famTypeStr $_GET['fam'];
    $subgeoStr $_GET['subgeo'];

    $con mysql_connect(/*CONNECTION DETAILS HERE*/);

        if (!
    'Could not connect: ' mysql_error());

    mysql_query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'");

    $sql="SELECT * FROM `householdinfo_" $year "` WHERE geography ='99' && subgeography ='" $subgeoStr"' && familytype LIKE'" $famTypeStr "%'";

    $result mysql_query($sql);
    $row mysql_fetch_array($result))
    $row['geography'] . ";" $row['subgeography'] . ";" $row['familytype'] . ";" $row['familycount'] . ";" $row['medianincome']; 

    However, because of the way drupal formats these nodes and prints them, I get the following text back in my "responsetext".

    HTML Code:
    <!-- start node.tpl.php -->
    <div id="node-36893" class="node odd full-node node-type-page">
      <div class="meta">
      <div class="content">
        99;1;C02 - COUPLE FAMILIES WITH 1 CHILDREN < 18;769980;76900  </div>
    <!-- /#node-36793 --> 
    The data that I am interested in here is the line inside of the "content" div. I would like to store this data inside a javascript array.

    Is there an easy way to modify either the PHP code to return just the inner HTML of the "content" div and not all of the other formatting, OR is there simple way to parse this data out once I have it stored in a javascript "data" variable.

    Thanks for all the help!

  2. #2
    Join Date
    Feb 2003
    Michigan, USA

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center