Jump to content

trying to get xml from javascript function but everything is undefined?


tyweed

Recommended Posts

So I have this xml which was created in php file by concatenating a string to create the xml myself:

<table>
<row>
<nameBet>
will Mike puke San Luis Obispo weekend party! Steve (No) Kenny (yes)	</nameBet>
<betBetween>
2	</betBetween>
<amount>
5	</amount>
<winner>
1	</winner>
<betId>
24	</betId>
<betCreator>
1	</betCreator>
<dateOfBet>
24-Apr-2008	</dateOfBet>
</row>
<row>
<nameBet>
Sharks (Ken) vs Flames (Steve) game 7	</nameBet>
<betBetween>
2	</betBetween>
<amount>
5	</amount>
<winner>
2	</winner>
<betId>
23	</betId>
<betCreator>
1	</betCreator>
<dateOfBet>
23-Apr-2008	</dateOfBet>
</row>
</table>


 

This is the php that creates the xml

   echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
                       $this->grid .= "<table>\n";
                      while($row = mysql_fetch_assoc($r))
				  {

                           $this->grid .= "<row>\n";

                           foreach($row as $name => $value)
                           {
                              //print "foreach: " . $name . " " . $value . "</br>";
                              $this->grid .= "\t<". $name. ">\n".
                                                  $value .
                                             "\t</". $name . ">\n";

                              if($filter == "myBets")
                          {
							if( ($name == "betCreator") && ($value == $user_id))
							{
							  $this->grid .= "\t<editDelete>\n".
				           //<a href=\'EditBet.php?id=\".$row['betId']."'>Edit Bet</a>
							//  | <a href='DeleteBet.php?id=".$row['betId']."'> Delete Bet</a> .
                                                 "\t</editDelete>\n";


							}

     				       }


                           }

                              $this->grid .= "</row>\n";


   				    }//end while

                                            $this->grid .= "</table>\n";

   				    return $this->grid;

    }

 

And finally the javascript i'm having the trouble with

 

function ajaxRequest(url,params) {

  var aj = new Ajax.Request(
  url, {
   method:"post",
   parameters: params,
   onComplete: getResponse
   }
  );

}
/* ajax.Response */
function getResponse(oReq) {

  //var result = oReq.responseText;
  var result = oReq.responseXML;
var row = result.documentElement.getElementsByTagName("row");

alert(row);  <=== undefined

 

So the problem is i'm unable to figure out how to grab the data from this xml. I have tried everything and searched everywhere.  If i print result it shows [object xmldocument] . But anything else gives me undefined any ideas why? I tried formating the headers in php that did not seem to help. If i do responseText it prints the xml formated file? If i write my xml to a file and open in ie and mozilla it opens fine like an xml file?

 

Forgot to mention i'm using prototype for ajax call for ease of use. but i don't think its a prototype problem......

 

I'm so lost and frustrated!

thats what i'v tried the code above shows i tried

 

var row = result.documentElement.getElementsByTagName("row");

 

where result is the responseXML.

 

I noticed most load the xml into a method i have not. I just assume that it's already loaded into the responseXML

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.