Skip to main content
Rollback to Revision 1
Source Link
Gordon
  • 317.8k
  • 76
  • 548
  • 566
 var xmlHttpObj=null; var isPostBack=false; function CreateXmlHttpRequestObject( ) { if (window.XMLHttpRequest) { xmlHttpObj=new XMLHttpRequest() } else if (window.ActiveXObject) { xmlHttpObj=new ActiveXObject("Microsoft.XMLHTTP") } return xmlHttpObj; } function MakeHTTPCall_Tags() { var link = "http://phpdev2.dei.isep.ipp.pt/~i110815/recebeXml.php"; xmlHttpObj = CreateXmlHttpRequestObject(); xmlHttpObj.open("GET", link, true); xmlHttpObj.onreadystatechange = stateHandler_Tags; xmlHttpObj.send(null); } function stateHandler_Tags() {  if ( xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200) {  alert("dsadas");   var selectTags = document.getElementById("tag");   var option;   var docxml = xmlHttpObj.responseXML;   var namesnodelist = docxml.splitgetElementById(",""name");   alert(namesnodelist.length); } } 
 <?php header("Access-Control-Allow-Origin: * "); // pedido ao last.fm com a função file_gets_contents // a string XML devolvida pelo servidor last.fm fica armazenada na variável $respostaXML $respostaXML= file_get_contents("http://ws.audioscrobbler.com/2.0/?method=tag.getTopTags&ap i_key=5bc5d54260065f88eb0e97897aa53a0f"getTopTags&api_key=4399e62e9929a254f92f5cde4baf8a16");     // criar um objecto DOMDocument e inicializá-lo com a string XML recebida $newXML= new DOMDocument('1.0', 'ISO-8859-1'); $newXML->loadXML($respostaXML); // navegar no XML com os métodos que já conhece, mas com uma sintaxe PHP para // aceder a objectos(->) $nodelist=$newXML->getElementsByTagName("name");  $tags="";    for ($i=0;$i<$nodelist->length;$i++) { $tagNode=$nodelist->item($i); $tagValue = $tagNode->nodeValue; $tags.=$tagValue . ","; } // para teste echo $tags; $newXML; ?> 

The PHP file isn't receivingI'm getting this error from the XML data correctly.browser console: GET http://phpdev2.dei.isep.ipp.pt/~i110815/recebeXml.php 500 (Internal Server Error) Anybody knows whats wrong?

 var xmlHttpObj=null; var isPostBack=false; function CreateXmlHttpRequestObject( ) { if (window.XMLHttpRequest) { xmlHttpObj=new XMLHttpRequest() } else if (window.ActiveXObject) { xmlHttpObj=new ActiveXObject("Microsoft.XMLHTTP") } return xmlHttpObj; } function MakeHTTPCall_Tags() { var link = "http://phpdev2.dei.isep.ipp.pt/~i110815/recebeXml.php"; xmlHttpObj = CreateXmlHttpRequestObject(); xmlHttpObj.open("GET", link, true); xmlHttpObj.onreadystatechange = stateHandler_Tags; xmlHttpObj.send(null); } function stateHandler_Tags() {  if ( xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200) {  alert("dsadas");   var selectTags = document.getElementById("tag");   var option;   var docxml = xmlHttpObj.responseXML;   var names = docxml.split(",");   alert(names.length); } } 
 <?php header("Access-Control-Allow-Origin: * "); // pedido ao last.fm com a função file_gets_contents // a string XML devolvida pelo servidor last.fm fica armazenada na variável $respostaXML $respostaXML= file_get_contents("http://ws.audioscrobbler.com/2.0/?method=tag.getTopTags&ap i_key=5bc5d54260065f88eb0e97897aa53a0f");  // criar um objecto DOMDocument e inicializá-lo com a string XML recebida $newXML= new DOMDocument('1.0', 'ISO-8859-1'); $newXML->loadXML($respostaXML); // navegar no XML com os métodos que já conhece, mas com uma sintaxe PHP para // aceder a objectos(->) $nodelist=$newXML->getElementsByTagName("name");  $tags="";    for ($i=0;$i<$nodelist->length;$i++) { $tagNode=$nodelist->item($i); $tagValue = $tagNode->nodeValue; $tags.=$tagValue . ","; } // para teste echo $tags;  ?> 

The PHP file isn't receiving the XML data correctly.

var xmlHttpObj=null; var isPostBack=false; function CreateXmlHttpRequestObject( ) { if (window.XMLHttpRequest) { xmlHttpObj=new XMLHttpRequest() } else if (window.ActiveXObject) { xmlHttpObj=new ActiveXObject("Microsoft.XMLHTTP") } return xmlHttpObj; } function MakeHTTPCall_Tags() { var link = "http://phpdev2.dei.isep.ipp.pt/~i110815/recebeXml.php"; xmlHttpObj = CreateXmlHttpRequestObject(); xmlHttpObj.open("GET", link, true); xmlHttpObj.onreadystatechange = stateHandler_Tags; xmlHttpObj.send(); } function stateHandler_Tags() { if ( xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200) { var selectTags = document.getElementById("tag"); var option; var docxml = xmlHttpObj.responseXML; var nodelist = docxml.getElementById("name"); alert(nodelist.length); } } 
<?php header("Access-Control-Allow-Origin: * "); // pedido ao last.fm com a função file_gets_contents // a string XML devolvida pelo servidor last.fm fica armazenada na variável $respostaXML $respostaXML= file_get_contents("http://ws.audioscrobbler.com/2.0/?method=tag.getTopTags&api_key=4399e62e9929a254f92f5cde4baf8a16");    // criar um objecto DOMDocument e inicializá-lo com a string XML recebida $newXML= new DOMDocument('1.0', 'ISO-8859-1'); $newXML->loadXML($respostaXML); echo $newXML; ?> 

I'm getting this error from the browser console: GET http://phpdev2.dei.isep.ipp.pt/~i110815/recebeXml.php 500 (Internal Server Error) Anybody knows whats wrong?

added 401 characters in body
Source Link
Adam Silva
  • 1k
  • 20
  • 53
 var xmlHttpObj=null; var isPostBack=false; function CreateXmlHttpRequestObject( ) { if (window.XMLHttpRequest) { xmlHttpObj=new XMLHttpRequest() } else if (window.ActiveXObject) { xmlHttpObj=new ActiveXObject("Microsoft.XMLHTTP") } return xmlHttpObj; } function MakeHTTPCall_Tags() { var link = "http://phpdev2.dei.isep.ipp.pt/~i110815/recebeXml.php"; xmlHttpObj = CreateXmlHttpRequestObject(); xmlHttpObj.open("GET", link, true); xmlHttpObj.onreadystatechange = stateHandler_Tags; xmlHttpObj.send(null); } function stateHandler_Tags() {  if ( xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200) {  alert("dsadas");   var selectTags = document.getElementById("tag");   var option;   var docxml = xmlHttpObj.responseXML;   var nodelistnames = docxml.getElementByIdsplit("name"",");   alert(nodelistnames.length); } } 
 <?php header("Access-Control-Allow-Origin: * "); // pedido ao last.fm com a função file_gets_contents // a string XML devolvida pelo servidor last.fm fica armazenada na variável $respostaXML $respostaXML= file_get_contents("http://ws.audioscrobbler.com/2.0/?method=tag.getTopTags&api_key=4399e62e9929a254f92f5cde4baf8a16"getTopTags&ap i_key=5bc5d54260065f88eb0e97897aa53a0f");    // criar um objecto DOMDocument e inicializá-lo com a string XML recebida $newXML= new DOMDocument('1.0', 'ISO-8859-1'); $newXML->loadXML($respostaXML); // navegar no XML com os métodos que já conhece, mas com uma sintaxe PHP para // aceder a objectos(->) $nodelist=$newXML->getElementsByTagName("name");  $tags="";    for ($i=0;$i<$nodelist->length;$i++) { $tagNode=$nodelist->item($i); $tagValue = $tagNode->nodeValue; $tags.=$tagValue . ","; } // para teste echo $newXML;$tags;  ?> 

I'm getting this error fromThe PHP file isn't receiving the browser console: GET http://phpdev2.dei.isep.ipp.pt/~i110815/recebeXml.php 500 (Internal Server Error) Anybody knows whats wrong?XML data correctly.

var xmlHttpObj=null; var isPostBack=false; function CreateXmlHttpRequestObject( ) { if (window.XMLHttpRequest) { xmlHttpObj=new XMLHttpRequest() } else if (window.ActiveXObject) { xmlHttpObj=new ActiveXObject("Microsoft.XMLHTTP") } return xmlHttpObj; } function MakeHTTPCall_Tags() { var link = "http://phpdev2.dei.isep.ipp.pt/~i110815/recebeXml.php"; xmlHttpObj = CreateXmlHttpRequestObject(); xmlHttpObj.open("GET", link, true); xmlHttpObj.onreadystatechange = stateHandler_Tags; xmlHttpObj.send(); } function stateHandler_Tags() { if ( xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200) { var selectTags = document.getElementById("tag"); var option; var docxml = xmlHttpObj.responseXML; var nodelist = docxml.getElementById("name"); alert(nodelist.length); } } 
<?php header("Access-Control-Allow-Origin: * "); // pedido ao last.fm com a função file_gets_contents // a string XML devolvida pelo servidor last.fm fica armazenada na variável $respostaXML $respostaXML= file_get_contents("http://ws.audioscrobbler.com/2.0/?method=tag.getTopTags&api_key=4399e62e9929a254f92f5cde4baf8a16");  // criar um objecto DOMDocument e inicializá-lo com a string XML recebida $newXML= new DOMDocument('1.0', 'ISO-8859-1'); $newXML->loadXML($respostaXML); echo $newXML; ?> 

I'm getting this error from the browser console: GET http://phpdev2.dei.isep.ipp.pt/~i110815/recebeXml.php 500 (Internal Server Error) Anybody knows whats wrong?

 var xmlHttpObj=null; var isPostBack=false; function CreateXmlHttpRequestObject( ) { if (window.XMLHttpRequest) { xmlHttpObj=new XMLHttpRequest() } else if (window.ActiveXObject) { xmlHttpObj=new ActiveXObject("Microsoft.XMLHTTP") } return xmlHttpObj; } function MakeHTTPCall_Tags() { var link = "http://phpdev2.dei.isep.ipp.pt/~i110815/recebeXml.php"; xmlHttpObj = CreateXmlHttpRequestObject(); xmlHttpObj.open("GET", link, true); xmlHttpObj.onreadystatechange = stateHandler_Tags; xmlHttpObj.send(null); } function stateHandler_Tags() {  if ( xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200) {  alert("dsadas");   var selectTags = document.getElementById("tag");   var option;   var docxml = xmlHttpObj.responseXML;   var names = docxml.split(",");   alert(names.length); } } 
 <?php header("Access-Control-Allow-Origin: * "); // pedido ao last.fm com a função file_gets_contents // a string XML devolvida pelo servidor last.fm fica armazenada na variável $respostaXML $respostaXML= file_get_contents("http://ws.audioscrobbler.com/2.0/?method=tag.getTopTags&ap i_key=5bc5d54260065f88eb0e97897aa53a0f");   // criar um objecto DOMDocument e inicializá-lo com a string XML recebida $newXML= new DOMDocument('1.0', 'ISO-8859-1'); $newXML->loadXML($respostaXML); // navegar no XML com os métodos que já conhece, mas com uma sintaxe PHP para // aceder a objectos(->) $nodelist=$newXML->getElementsByTagName("name");  $tags="";    for ($i=0;$i<$nodelist->length;$i++) { $tagNode=$nodelist->item($i); $tagValue = $tagNode->nodeValue; $tags.=$tagValue . ","; } // para teste echo $tags;  ?> 

The PHP file isn't receiving the XML data correctly.

Source Link
Adam Silva
  • 1k
  • 20
  • 53

Get XML data from website inside PHP file (Internal Server Error)

I need to get XML data from a website using an API key, and I'm using AJAX and PHP. Here's my AJAX code (btw, the PHP file is inside a FileZilla server):

var xmlHttpObj=null; var isPostBack=false; function CreateXmlHttpRequestObject( ) { if (window.XMLHttpRequest) { xmlHttpObj=new XMLHttpRequest() } else if (window.ActiveXObject) { xmlHttpObj=new ActiveXObject("Microsoft.XMLHTTP") } return xmlHttpObj; } function MakeHTTPCall_Tags() { var link = "http://phpdev2.dei.isep.ipp.pt/~i110815/recebeXml.php"; xmlHttpObj = CreateXmlHttpRequestObject(); xmlHttpObj.open("GET", link, true); xmlHttpObj.onreadystatechange = stateHandler_Tags; xmlHttpObj.send(); } function stateHandler_Tags() { if ( xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200) { var selectTags = document.getElementById("tag"); var option; var docxml = xmlHttpObj.responseXML; var nodelist = docxml.getElementById("name"); alert(nodelist.length); } } 

Here's the PHP code:

<?php header("Access-Control-Allow-Origin: * "); // pedido ao last.fm com a função file_gets_contents // a string XML devolvida pelo servidor last.fm fica armazenada na variável $respostaXML $respostaXML= file_get_contents("http://ws.audioscrobbler.com/2.0/?method=tag.getTopTags&api_key=4399e62e9929a254f92f5cde4baf8a16"); // criar um objecto DOMDocument e inicializá-lo com a string XML recebida $newXML= new DOMDocument('1.0', 'ISO-8859-1'); $newXML->loadXML($respostaXML); echo $newXML; ?> 

I'm getting this error from the browser console: GET http://phpdev2.dei.isep.ipp.pt/~i110815/recebeXml.php 500 (Internal Server Error) Anybody knows whats wrong?