Трудно найти, когда я публикую XML-документ на моем сайте - PullRequest
0 голосов
/ 04 июня 2009

Я использую php и javascript коды для публикации моего xml на URL. и я успешно опубликовал его с моего локального сервера. но когда я попробовал это на сайте, я не могу опубликовать свой документ XML на этот URL. что будет причиной этого ??? почему это происходит, прекрасно работает на моем локальном сервере, но ничего не происходит на сайте. Я должен сделать это с PHP и JavaScript. Может кто-нибудь мне помочь???? ниже приведен код, который я использовал.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
          "http://www.w3.org/TR/html4/strict.dtd">
<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>

Может ли кто-нибудь помочь мне в этом вопросе .........

Ответы [ 2 ]

0 голосов
/ 09 июля 2009

Кроме того, действительно ли необходимо иметь так много объявлений, просто потому, что JavaScript - это разные версии?

0 голосов
/ 04 июня 2009

У вас есть права на загрузку файла правильно? Это также может быть некоторая конфигурация на сайте сервера (параметры безопасности, отсутствующее расширение и т. Д.).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...