Link to home
Start Free TrialLog in
Avatar of Bruj
BrujFlag for United States of America

asked on

Auto request XML or JSON for a webpage

I want to write a web page that requests an xml or json request every hour from another site and then parse and update fields
I have written general pages that are static in nature, but now I want to write on that auto updates every how with new data pulled from another site which returns the data in either json or xml.
I am not sure how I would do this.
I am looking for some basic samples or a good tutorial for this type of action.

Thanks, Bruce
Avatar of David Favor
David Favor
Flag of United States of America image

You wouldn't to this via "writing a webpage".

You'd write a script, likely in PHP to leverage Opcache... or better just run curl... as pulling a simple Webpage likely requires no code.

The script would run every hour to pull down your data (XML or JSON or YAML or whatever).

Then if required, the script would generate a webpage on your server to represent the data you pulled.
Hi,

I would use a cron job (linux) or task scheduler (windows) to run a PHP / AJAX script that will fetch the new data from JSON or XML.
Check with your hosting company in cpanel, plesk... there usually a place where you can set a cron job.
If not you can use a free online service https://cron-job.org/

Depending from where you are taking the data you may be able to use their API.

To learn JSON / XML here is one of the best instuctor
Laurence Svekis
https://www.udemy.com/user/lars51/
Basically, you simply set a timer and execute an AJAX call. But this would mean that you need to look cross site origin resource sharing (CORS).

Thus you may also evaluate quering the data on the back-end and using technologies like SignalR to push updates.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.