Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Do AJAX calls not work everytime?

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never known it to be intermittent. And no, I don't use IE so I can't look at your page.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic