/    Sign up×
Community /Pin to ProfileBookmark

Reload XML for reading.

I have searched like crazy and can’t find or don’t understand the solutions to reloading an XML file that I’m reading with AJAX.

I’m looking for a way to refresh this XML when the page is refreshed so I know that the data is up to date. It only needs to happen when the page is reloaded.

one solution suggested something like this

[CODE]var xmlhttp;
function loadNewsContent(url)
{
var nocache = Math.random();//fix for IE who keeps the requested file in cache

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=stateChange;
xmlhttp.open(“GET”,url+’&nocache=’+nocache,true);
xmlhttp.send(null);
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
xmlhttp.onreadystatechange=stateChange;
xmlhttp.open(“GET”,url+’&nocache=’+nocache,true);
xmlhttp.send();
}
}
[/CODE]

But that doesn’t work at all and I don’t know why. I’m new to this stuff so please try and provide complete answers as I have seen a pile of answers that just say “use this line..” and I can’t make heads or tails of it.

Thanks.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@NicTltMay 10.2010 — Do you have a stateChange function?
Copy linkTweet thisAlerts:
@penauthorMay 11.2010 — Yes, fairly standard fair. Should I be calling something in here to reload the XML? Doesn't make much sense as at this point the XML has already been read.

Do you have a solution to the problem?

[CODE]function stateChange()
{
if (xmlhttp.readyState==4)
{
if (xmlhttp.status==200)
{
...
[/CODE]
Copy linkTweet thisAlerts:
@NicTltMay 11.2010 — If the feed's not on your own domain, then it won't get fetched.

Have a search on this forum for "YQL" and it should resolve this and your caching problem.
Copy linkTweet thisAlerts:
@penauthorMay 11.2010 — Looks like the search will not work on that short of a string, I don't get anything being returned. Any other suggestions on the search?
Copy linkTweet thisAlerts:
@penauthorMay 11.2010 — Is this Yahoo Query Language?

Never heard of this. Can you explain to me how this is going to solve the problem of me getting an update on the XML file?
×

Success!

Help @pen spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...