views:

307

answers:

2

hi friends

I am using a php and javascript codes to post my xml to a url. and i have posted it successfully from my local server. but when i tried it in site, i cant post my xml document to that url. what will be the reason for it??? why this is happening, working perfectly in my local server but nothing is happening in the site. i have to do this with php and javascript. can any one help me???? below is the code which i have used.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd"&gt;
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
XML parsing, serialization, asynchronous HTTP POST data exchange
</title>
<script type="text/javascript">
/* dummy implementations for those browsers not having XML support */
function createXMLFromString (string) {
  output('XML not implemented.');
  return null;
}

function serializeXML (xmlDocument) {
  output('XML not implemented.');
  return '';
}

function postXML (url, xmlDocument) {
var httpRequest;
  try {

 httpRequest = new ActiveXObject(Msxml2.XMLHTTP);
   alert("gfh")
 httpRequest.open('POST', url, true);
 httpRequest.onreadystatechange = function () {
   if (httpRequest.readyState == 4) {
  responseHandler(httpRequest);
   }
 };
 httpRequest.send(xmlDocument);
 return httpRequest;
  }
  catch (e) {

 output("XML not implemented.");
 return null;
  }
}

function output (text) {
  var p, layer;
  if (document.createElement && (p = document.createElement('p'))) {
 p.appendChild(document.createTextNode(text));
 document.body.appendChild(p);
  }
  else if (typeof Layer != 'undefined' && (layer = new
Layer(window.innerWidth))) {
 layer.top = document.height;
 layer.left = 0;
 layer.document.open();
 layer.document.write('<p>' + text + '<\/p>');
 layer.document.close();
 layer.visibility = 'show';
 document.height += layer.clip.height;
  }
}
</script>
<script type="text/jscript">
function createXMLFromString (string) {
  var xmlDocument;
  try {
 xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
 xmlDocument.async = false;
 xmlDocument.loadXML(string);
 return xmlDocument;
  }
  catch (e) {
 output("Can't create XML document.");
 return null;
  }
}

function serializeXML (xmlDocument) {
  return xmlDocument.xml;
}

function postXML (url, xmlDocument, responseHandler) {
  var httpRequest;
  try {
 httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
 httpRequest.open('POST', url, true);
 httpRequest.onreadystatechange = function () {
   if (httpRequest.readyState == 4) {
  responseHandler(httpRequest);
   }
 };
 httpRequest.send(xmlDocument);
 return httpRequest;
  }
  catch (e) {
 output("Can't post XML document.");
 return null;
  }
}
</script>
<script type="text/javascript; version=1.5">
function createXMLFromString (string) {
  var xmlParser, xmlDocument;
  try {
 xmlParser = new DOMParser();
 xmlDocument = xmlParser.parseFromString(string, 'text/xml');
 return xmlDocument;
  }
  catch (e) {
 output("Can't create XML document.");
 return null;
  }
}

function serializeXML (xmlDocument) {
  var xmlSerializer;
  try {
 xmlSerializer = new XMLSerializer();
 return xmlSerializer.serializeToString(xmlDocument);
  }
  catch (e) {
 output("Can't serialize XML document.");
 return '';
  }
}

function postXML (url, xmlDocument, responseHandler) {

  try {

 var httpRequest = new XMLHttpRequest();

 httpRequest.open('POST', url, true);
 httpRequest.onreadystatechange = function () {
   if (httpRequest.readyState == 4) {
  responseHandler(httpRequest);
   }
 };
 httpRequest.send(xmlDocument);
 return httpRequest;
  }
  catch (e) {
 try{

  var httpRequest = new ActiveXObject(Msxml2.XMLHTTP);
 httpRequest.open('POST', url, true);

 httpRequest.onreadystatechange = function () {
   if (httpRequest.readyState == 4) {
  responseHandler(httpRequest);
   }
 };
 httpRequest.send(xmlDocument);
 return httpRequest;
 }catch (e){
 output("Can't post XML document");
 return null;
 }
  }
}
</script>
<script type="text/javascript">
/* Here starts the code to perform some tests with the script functions
   defined above.
*/
function testXMLDocumentCreationFromString () {
  var xmlDocument = 
  createXMLFromString('<gods><god name="Kibo" \/><\/gods>');
  if (xmlDocument) {
 output('Parsing from string results in: ' + xmlDocument);
 output('xmlDocument.documentElement.nodeName: ' + 
   xmlDocument.documentElement.nodeName);
 var xibo = xmlDocument.createElement('god');
 xibo.setAttribute('name', 'Xibo');
 xmlDocument.documentElement.appendChild(xibo);
 output(
'xmlDocument.documentElement.lastChild.getAttribute("name"): ' +
     xmlDocument.documentElement.lastChild.getAttribute("name"));
  }
  return xmlDocument;
}

function testXMLDocumentSerialization (xmlDocument) {
  if (xmlDocument) {
 output(xmlDocument + ' serialized has markup: ' +
serializeXML(xmlDocument));
  }
}

function exampleResponseHandler (httpRequest) {
  output('HTTP response status: ' + httpRequest.status);
  output('Response as text: ' + httpRequest.responseText);
  output('responseXML.documentElement.nodeName: ' +
   httpRequest.responseXML.documentElement.nodeName);
}

function testXMLPosting (url, xmlDocument, responseHandler) {

  if (xmlDocument) {
 var httpRequest = postXML(url, xmlDocument, responseHandler);
 output('Trying to HTTP POST ' + xmlDocument + ' to ' + url +
     ' results in: ' + httpRequest);
  }
}

window.onload = function (evt) {
 var xmlDocument ="my xml document";
  //testXMLDocumentSerialization(xmlDocument);
  testXMLPosting('myurl', xmlDocument,exampleResponseHandler);
};
</script>
</head>
<body>
<h1>XML parsing, serialization, asynchronous HTTP POST data exchange</h1>
</body>
</html>

can any one help me in this issue.........

A: 

Do you have permissions to upload the file right? It could also be some configuration on the server site (security options, missing extension, etc).

Victor
A: 

Also, is it really necessary to have so many <script> declarations, just because the JavaScript's are different versions?

Pedro Cunha