0

Since Google's feed load service was turned off, I'm struggling to find a new way to display xml feeds across different protocols and domains. I need to feed in a blog onto a website. The website is https, the blog is not. I have a some success here, but only in getting the title. I need to wrap the title in the link, and insert it into a li. Got that working, need to get it into DOM

Here is my proxy the path is (/SSI/Processor/feedProxy.php):

<?php
    function download_page($path){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$path);
    curl_setopt($ch, CURLOPT_FAILONERROR,1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    $retValue = curl_exec($ch);          
    curl_close($ch);
    return $retValue;
}

$sXML = download_page('https://www.external.com/feeds/feed.xml');
$oXML = new SimpleXMLElement($sXML);

$items = $oXML->entry;
$i = 0;
foreach($items as $item) {
    $title = $item->title;
    $link = $item->link;
    echo '<li>';
    foreach($link as $links) {
    $loc = $links['href'];
    echo "<a href=\"$loc\">";
}
echo $title;
echo "</a>";;
echo "</li>";
if(++$i == 3) break;
}
?>

Edit

I can now get all the xml returned, and formatted via PHP. I just can't insert it into DOM with jQuery!

And my jQuery:

$(function(){
    $.ajax({
    type: "GET",
    url:'/SSI/Processor/feedProxy.php',
    dataType: "html",
    success: function(html) {
        console.log(html);
        //console log is showing the formatted HTML
        $('#feeds').html(html);
    });
});

I am struggling with how to parse it in PHP. It needs to output like this: <li><a href="linkfromxml">link text</a></li> and append that to a div.

6
  • 1
    sorry, i misread it due to inconsistent formatting Commented Jan 18, 2017 at 1:15
  • 1
    not sure why you are asking form xml in ajax when you are really sending html Commented Jan 18, 2017 at 1:16
  • I apologize for the formatting. I have edited the question to ask for html Commented Jan 18, 2017 at 1:17
  • 1
    but your dataType is still xml. Commented Jan 18, 2017 at 1:18
  • That fixed it. I wish there was an easier way than using PHP cURL, I can't get the YQL version to work. Parsing JSON is much simpler. Commented Jan 18, 2017 at 1:23

1 Answer 1

1

You are returning html but you are setting the dataType to xml

Change it to dataType:'html'

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

Comments

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.