0

Due to white-list security I'm using a PHP script to return XML from an external server.

PHP file code looks as follows -

<?php

include_once 'utilityCurl.class.php';

$uri = 'http://OURSERVER/feeds/?feedID=99&c';

$response = utilityCurl::fetchContent($uri);

echo $response;

It uses the curl to return xml file.

I then use a jQuery ajax xml script to parse -

        $.ajax({ 
                    type: "GET", 
                    url: "http://fb.mobilechilli.com/chilli_news_reviews/news_feed_retrival.php", 
                    dataType: "xml", 
                    success: parseXml, 
                    error: errorMsg 

            }); 
//Once xml parsed and entered onto page - run caroufred class that makes the carousel work.     






            function parseXml(xml) 
            { 

                    $(xml).find("NewsItem").each(function() 
                    { 
                            var title = $(this).find('HeadLine').text();
                            var artist = $(this).find('NewsLineType').text();
                            var listItem = $('<p>hello '+title+'</p><p>'+artist+'</p><br/>');                               
                            $(".newsHeader").append(listItem);
                    });
                    alert("yep");

            }
            function errorMsg() { 
                    alert("error getting xml feed"); 
            } 
         });

Unfortunately I just get the error message displayed!

can anybody advise where i'm gong wrong?

Thanks Paul

8
  • Did you get any error in Firebug console? Commented Aug 9, 2011 at 15:54
  • no annoyingly not -firebug states all is fine! Commented Aug 9, 2011 at 15:59
  • Does it show the request is being made, and correct response? Commented Aug 9, 2011 at 15:59
  • If i switch the datatype to php it doesnt error - but stil doesnt display anything! Commented Aug 9, 2011 at 16:00
  • Yes request is made and receives a response. I will upload as an example Commented Aug 9, 2011 at 16:01

1 Answer 1

1

json would be a lot easier to work with here.

in php dump this instead

echo json_encode(simplexml_load_string($xml));

then in javascript you can just check if json.NewsItem is populated with something

Sign up to request clarification or add additional context in comments.

2 Comments

sorry my knowledge of json with jquery isnt very strong, i've no idea how to call for and parse the xml file with json? I added the echo script to the php file but still get the same error?
sorry, I missed a line in my example code. You should echo the json_encode(simplexml_load_string($xml)) into your page then in javascript you get the result as json and just reference it like an object ie json.NewsItem will be an array of objects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.