How do I Use Ajax to grab Blogger data

Get help using Construct 2

Post » Tue Sep 08, 2015 4:27 pm

Goal: Figure out how to read RSS or ATOM Feed from blogspot and output XML content to inform users of future updates & news, along with quick messages to the user base.

The Problem I am having: getting nothing but the "on ajax error" exception I put in to change the bg color & text.

I am trying to grab it from this feed:
http://undeadbobop.blogspot.com/feeds/posts/default

Which is more clear with online xml formatters, which shows I need to grab from feed/entry/title & feed/entry/content.
Basically I am trying to make a RSS feed reader and I don't see what I am doing wrong.

Link to source: https://www.dropbox.com/s/z8hs1ucncmvn8bo/xmltry.capx?dl=0

And Yes I am trying it inside exported projects too.
Need custom controls, video & sound options, and a PC like menu system with screenshot manager?
Image
B
20
S
4
G
2
Posts: 36
Reputation: 2,440

Post » Tue Sep 08, 2015 6:41 pm

Normally you cannot grab data by AJAX from different domain than the one the request is triggered from. So if you are trying to fetch data across different domains you need to tell your webserver to allow it.

If you use Apache then simply create .htaccess file and put the following line inside:
Code: Select all
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
ImageImageImage
B
27
S
16
G
74
Posts: 977
Reputation: 41,673

Post » Tue Sep 08, 2015 8:30 pm

Well thank you for telling me this, it isn't much help since I don't have a webserver and most webhosts won't allow you to configure it unless you pay for them.
Need custom controls, video & sound options, and a PC like menu system with screenshot manager?
Image
B
20
S
4
G
2
Posts: 36
Reputation: 2,440

Post » Tue Sep 08, 2015 9:03 pm

You can do a workaround with a small PHP script.

Code: Select all
<?php
header("Access-Control-Allow-Origin: *");
$rss = file_get_contents('http://undeadbobop.blogspot.com/feeds/posts/default');
die($rss);
?>


Now you can grab your PHP file with AJAX in C2. The result will be the same.

EDIT: I'm sure both solutions will work on most of free PHP servers.
ImageImageImage
B
27
S
16
G
74
Posts: 977
Reputation: 41,673


Return to How do I....?

Who is online

Users browsing this forum: David181, evillair and 59 guests