*
The moose likes HTML, CSS and JavaScript and the fly likes Do AJAX calls not work everytime?  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Do AJAX calls not work everytime?  " Watch "Do AJAX calls not work everytime?  " New topic
Author

Do AJAX calls not work everytime?

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
I have my AJAX set up to send a username of a character from World of Warcraft to several of my .php files. What I do is file_get_contents for that character's armory link (http://www.wowarmory.com/character-sheet.xml?r=Korgath&cn=X).

Needless to say I parse the text and get the info I need to make my own mini-armory.

now on my page sometimes when I click on a certain user, everything will work just fine, then on the other hand sometimes it won't but if I close the browser and try that same character's armor again, it works fine.

I was just wondering if AJAX sometimes just gets overloaded and bombs out, or if there is some special code I need to put in to insure my responseText is returned.

The page I made is http://www.newfazeindustries.com/guild/guildarmory/guildarmory/index.php (use IE, FF doesn't work lol).

Thanks,

Justin


You down with OOP? Yeah you know me!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

I have never known it to be intermittent. And no, I don't use IE so I can't look at your page.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
I mean, it simi-works in ff, enough for you to get the concept of what I'm doing. The armor image thumbnails are sent back in one ajax call, the health/mana in one and their main professions (mining,skinning,enchanting and etc) in one and the stats on that piece of gear when you hover in another(the stats are supposed to pop up in a div when you onmouseenter, but doesn't seem to work in ff).

Sometimes it all works fine and then sometimes the health won't show up, or the amor won't change for that person.

If AJAX doesn't tend to mess up sometimes, then I'm obviously going about this the wrong way... here is an example of my ajax functions:







I've done AJAX before, but I guess I could've bit the dust on this try.

thanks again,

Justin
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
if you use get, I am guessing you are having caching issues. Maybe a request failed/came back incomplete and it keeps serving that back to you.

Eric
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
is it possible to clear the cache using javascript or by some other means? Having to re-open the browser is a pain.

Thanks
Peter Jennings
Greenhorn

Joined: Sep 25, 2009
Posts: 9
Justin Fox wrote:is it possible to clear the cache using javascript or by some other means? Having to re-open the browser is a pain.

Thanks


The traditional solution is to append random characters to the URL you are getting so that the browser won't recognize it as being the same URL.

google: prevent ajax cache for many solutions.

If you are using jquery, you can use this to prevent caching of ajax gets.


Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
Cool, I just appended "&ms="+ new Date().getTime();
to all my request object's urls.

Seems to be doing the job better.

Thanks,

Justin
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Interesting demo, Justin. Do you have a bigger purpose planned for this or are you just using this to learn? I mean, you are just duplicated the official armory.


GenRocket - Experts at Building Test Data
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
Well it's for our guild site, rather that going to wowarmory, searching a guild members name, then looking for the corresponding realm, you can just go to the guild site, click on members, then look at everyone's gear and class etc..

The only think I can't get to work properly is the Armor-Stats popup in firefox, it keeps flashing on and off really fast. In IE it works good though.

Just a way of representing the same data in an more accessible way for a particular guild.

Justin

p.s.
but yes I'm learning stuff too lol
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Using a decent JavaScript library will help you quite a bit, although when bad things happen you may still need to know what's going on under the hood. But the library will help deal with cross-browser issues and make understanding the code much, much easier.

If for no other reason people are more likely to help you if the code is short :)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Indeed, why use 20+ lines of grody code to make an Ajax request when a single line of jQuery code will do the same thing?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Do AJAX calls not work everytime?