0

I want to show the status of a server from a XML file that is in a different domain, on a simple HTML page. I tried using jQuery but then i learned about the cross-domain restrictions. After Googling it i learned it can be done using PHP but i'm a bit lost since im a newbie with PHP.

My XML looks like this:

<status>
    <item name="ServerName1" online="True" locked="False" population="medium" queued="0" language="English" recommend="False" />
    <item name="ServerName1" online="True" locked="False" population="medium" queued="0" language="English" recommend="False" />
    <item name="ServerName3" online="True" locked="False" population="medium" queued="0" language="English" recommend="False" />
</status>

I tried this using jQuery, i need to do something similar using PHP:

        $(document).ready(function () {
            FetchServerData();
        });

        function FetchServerData(){
            $.ajax({
                type: 'GET',
                url: 'serverstatus.xml',
                //data: 't=' + Math.floor(Math.random() * 1000001),
                //headers : {Accept : "text/xml","Access-Control-Allow-Origin" : "domainwithxml.com"},
                dataType: 'xml',
                success: function (data) {
                    LoadServerData(data);
                }
            });
        }

        function LoadServerData(data){
            if (data != null) {
                $(data).find("item").each(function () {
                    var thisName = $(this).attr('name');

                    if(thisName == "Servername"){
                        var thisOnline = $(this).attr('online');
                        var thisPop = $(this).attr('population');

                        var onlineName = $("<p></p>").append(thisName);
                        var onlineParagraph = $("<p></p>").append(thisOnline);
                        $('#server').append(onlineName);
                        $('#server').append(onlineParagraph);

                    }           
                });
            }
        }

I want to show the name, online status and population status of ONE server only.

Thanks in advance.

1 Answers1

-1

You can use cURL in PHP to get the content of the other server, then use it on the server you are running PHP on to display it.

ronnied
  • 106
  • 1
  • 4