hi

The "X" in AJAX says that the data are XML Data.

To parse XML I use DOM.
It is also possible to validate the data using RelaxNG, DTD or XMLSchema
before processing.

A receiver in PHP looks like

<?php
//read the string ($HTTP_RAW_POST_DATA is by default 
//not active -> use "php://input")
$content=file_get_contents("php://input");

//make a dom object
//many people know DOM already from programming javascript
$dom=domDocument::loadXML($content);

//validate with DTD,RelaxNG or XMLSchema
//http://at.php.net/manual/de/function.dom-domdocument-relaxngvalidate.php
if($dom->relaxNGValidate("test.rng")){

  //than read the data you need
  //for example if your XML looks like
  //<person born="1935">
  //<firstname>Dalei</firstname><lastname>Lama</lastname>
  //</person>

  $firstname=$dom->getElementsByTagName('firstname')->item(0);
  $lastname=$dom->getElementsByTagName('lastname')->item(0);
  $born=$dom->documentElement->getAttribute('born');
}else{
  echo "data are not valid";
}
?>



If you don't like XML (AJAX) use JSON.

Bernhard



Am Donnerstag, den 25.01.2007, 00:00 -0700 schrieb M5:
> Just wondering what smart people do for parsing data sent by the  
> Javascript XMLHTTP object--e.g., http.send("post",url,true)...
> 
> In a normal form submit, the $_POST global nicely allocates form  
> elements as array elements automatically. But with the AJAX way, the  
> data get stuffed inside $HTTP_RAW_POST_DATA as a string, thereby  
> making extraction more tedious.
> 
> Any ideas?
> 
> ...Rene
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to