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://ift.tt/1yLeO8C";
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://ift.tt/1yLeO8G");

// 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://ift.tt/1yLeO8C 500 (Internal Server Error) Anybody knows whats wrong?


No comments:

Post a Comment