xmlhttp
function testXMLHTTP(){
var docXML = loadXMLDoc("dummy.xml", false);
postXMLDoc(docXML, "./echo.php", true);//"ciao"
}
///////////////// xmlhttp section ///////////////////
function initReq(){
if (window.req){
req.abort();
}
//delete req;
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
//"Msxml2.XMLHTTP.4.0"
//"Microsoft.XMLHTTP"
req = new ActiveXObject("Msxml2.XMLHTTP.4.0");
}
}
function postXMLDoc(doc, url, async){
//initReq();
//async = true;
if (async){
req.onreadystatechange = postReqChange;
}
req.open("POST", url, async);
req.setRequestHeader('content-type', 'text/xml');
req.send(doc);
if (!async){
alert("mandato: "+req.responseText);
}
else{
alert("aspetta");
}
}
function postReqChange() {
// only if req shows "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
alert(req.responseText);
} else {
alert("There was a problem retrieving the XML data:\n" +req.statusText);
}
}
}
///////////php script//////////////// (echo.php)
<?php
$sXML = $GLOBALS['HTTP_RAW_POST_DATA'];
echo "$sXML";
// Open a text file and erase the contents if any
$fp = fopen("posted.xml", "w");
// Write the data to the file
fwrite($fp, $sXML);
// Close the file
fclose($fp);
//$headers = getallheaders();
/*foreach ($headers as $name => $content) {
echo "$name = $content<br>n";
}*/
//echo "{$headers["my-header"]}";
?>
//////////////////////xml document////////////////////// (dummy.xml)
<progetto id="0"><schema id="schF0" tipo="schemaFunzionale"><schemaFunzionale/><oggetto id="imm0" tipo="immagine" x="50" y="50"><immagine nomeFile="cacca.jpg"/><etichettaAssociata id="etich0"/></oggetto><oggetto id="etich0" tipo="etichetta" x="100" y="100"><etichetta idOggettoEtichettato="imm0">commento cacca</etichetta></oggetto></schema></progetto>
|