开发者

using Jquery to parse xml returned from a PHP file

开发者 https://www.devze.com 2023-03-27 08:40 出处:网络
Due to white-list security I\'m using a PHP script to return XML from an external server. PHP file code looks as follows -

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"); 
            } 
         });

Un开发者_高级运维fortunately I just get the error message displayed!

can anybody advise where i'm gong wrong?

Thanks Paul


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

0

精彩评论

暂无评论...
验证码 换一张
取 消