I'm trying to extract the titles and descriptions from the MailChimp RSS feed using jQuery.
I'm trying with:
$.ajax({
type: 'GET',
url: 'http://us10.campaign-archive1.com/feed?u=21a65076da97205b5e5ff33e6&id=cc8bfc765e',
crossDomain: true,
dataType: 'jsonp',
success: function (xml) {
$(xml).find("item").each(function () {
var title = $(this).find("title").text();
var description = $(this).find("description").text();
var linkUrl = $(this).find("link_url").text();
var link = "<a href='" + linkUrl + "' target='_blank'>Read More<a>";
$('#feedContainer').append('<article><h3>' + title + '</h3><p>' + description + link + '</p>');
});
}
});
But I get the error:
Uncaught SyntaxError: Unexpected token < on
http://us10.campaign-archive1.com/feed?u=21a65076da97205b5e5ff33e6&id=cc8bfc765e&callback=jQuery214010618008393794298_1436280190025&_=1436280190026
If it's not possible through jQuery, is there another method? I tried with Yahoo Developer Console but robots.txt disallows the access..
It seems mailchimp disallow access that doesn't come from browsers, I tried to curl the URL and I get a 404 not found.
Click the Manage contacts drop-down and choose View archived contacts. On your archived contacts page, you can export all of your archived contacts, access their contact profile pages, or unarchive them as needed. Check the box next to each contact you want to unarchive. Click Unarchive.
Export your account dataClick your profile icon and choose Account. Click the Settings drop-down menu and choose Manage my data. Check the box next to each type of data you want to export and click Export Data. We'll bundle all of your data into a single ZIP file, which you can download from the Manage my data page.
To set up an RSS feed in Mailchimp, start an RSS campaign. Create an RSS campaign by navigating to the Automations icon on your account dashboard. From there, select Classic Automations and then click Share blog updates.
You need to parse XML before query with jquery (https://api.jquery.com/jQuery.parseXML)
var xmlDoc = $.parseXML(xml);
var $xml = $(xmlDoc);
$xml.find("item");
Set valid dataType to xml
Uncaught SyntaxError: Unexpected token < on http://us10.campaign-archive1.com/feed?u=21a65076da97205b5e5ff33e6&id=cc8bfc765e&callback=jQuery214010618008393794298_1436280190025&_=1436280190026
The above error is caused by the fact that JSONP requires the returned data to be valid JSON/javascript, which XML is not.
Unfortunately JSONP is needed in your case as CORS isn't enabled on this specific server. (see CORS for Apache)
The result is that you cannot use jQuery only if the returned data can be changed to JSON.
I just tried curl
, and it seems to work fine, no 404 error for me, maybe you need to use a proxy? And make sure your quote the url, as the character &
is handled specially in a shell.
curl 'http://us10.campaign-archive1.com/feed?u=21a65076da97205b5e5ff33e6&id=cc8bfc765e'
And if you're going to use curl, there would be more than one options to parse xml, such as xmllint, see How to parse XML using shellscript?
Here's an example using xmllint
:
xmllint --nocdata --xpath '//item[1]/title/text()' <(curl -s \
'http://us10.campaign-archive1.com/feed?u=21a65076da97205b5e5ff33e6&id=cc8bfc765e')
It prints the first title:
AVVIO ANNO SCOLASTICO 2015/2016
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With