我需要從這個(gè) URL 獲取 XML 數(shù)據(jù):http: //45.119.203.114 : 8888/xmltv.php?username=epg&password=epg 來(lái)解析 EPG 數(shù)據(jù)我曾嘗試使用 Javascript 和 PHP 但它不起作用這是我的代碼Javascriptvar xmlHttp = new XMLHttpRequest(); xmlHttp.open( "GET", 'http://45.119.203.114:8888/xmltv.php?username=epg&password=epg'); // false for synchronous request xmlHttp.responseType = 'document'; xmlHttp.setRequestHeader('Accept', 'application/xml'); xmlHttp.onload = function () { if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 ) { console.log(xmlHttp.responseXML); } } xmlHttp.send();我的 javascript 代碼中的結(jié)果始終是 No 'Access-Control-Allow-Origin'這是我的 PHP 代碼$path = 'http://tvku.live:8888/xmltv.php?username=epg&password=epg'; $xml=simplexml_load_file($path); $me = "sub-title"; foreach($xml->programme as $item){ echo "Start : " .date("G:i d.m.Y", strtotime(substr($item["start"], 0, -6))) . '<br>'; echo "End : " .date("G:i d.m.Y", strtotime(substr($item["stop"], 0, -6))) . '<br>'; echo "Channel : ".$item["channel"]. "<br>"; echo "Title : ".$item->title. "<br>"; echo "Info : ".$item->$me. "<br>"; echo "Description : ".$item->desc. "<br>"; echo "<br>"; }我的 php 代碼沒(méi)有結(jié)果,在我的 PHP 代碼中,我曾嘗試使用 CURL 獲取數(shù)據(jù),但也沒(méi)有效果請(qǐng)尋求您的幫助,謝謝
如何使用 GET 方法從 url 中獲取 xml 數(shù)據(jù)
眼眸繁星
2021-06-16 10:11:10