Fetching Item Data

90 Tauren Warrior
5390
I am currently trying to fetch information related to a simple item via javascript but simply cannot get it to work. I have successfully gotten Guild & Character information via JSON but I've read that items and other members of the API are not eligible for the same methods of retrieval. I've tried using an XMLHttpRequest but with no luck. Could anyone perhaps show me some code that will get information about an item. Perhaps I am just doing it wrong as my web experience is minimal. Thanks.

var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","http://us.battle.net/api/wow/item/38682",true);
xmlhttp.send();
alert(xmlhttp.responseText);
Reply Quote
1 Troll Rogue
0
You're bumping into the same origin policy. See this thread:

http://us.battle.net/wow/en/forum/topic/6893750295
Reply Quote
90 Tauren Warrior
5390
Doesn't appear to be the same issue. I can access player profiles and guild info via JSON just fine. It is ITEM RETRIEVAL I am struggling with. All that thread says is how to use JSON.
Reply Quote
90 Tauren Warrior
5390
Ah, same origin policy. I see now. I will try your suggestion in that thread. Thanks.
Reply Quote
90 Tauren Warrior
5390
I'm trying the below and it still doesn't work. Any ideas?

var s = document.createElement('script');
s.src = "http://us.battle.net/api/wow/item/38682&jsonp=bnetreturn";
s.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(s);

function bnetreturn(o) {
alert(o.id);
}
Reply Quote
1 Troll Rogue
0
change this line:
s.src = "http://us.battle.net/api/wow/item/38682&jsonp=bnetreturn";
to this:
s.src = "http://us.battle.net/api/wow/item/38682?jsonp=bnetreturn";
Reply Quote
90 Tauren Warrior
5390
You sir, are a gentleman and a scholar. Thanks.
Reply Quote
90 Human Paladin
14880
This is the difference between JSON and JSONP (JSON with Padding). JSONP is a workaround to get around same origin policy.

I wrote an article about this here for further reading:

http://www.strategytraderhelp.com/wow/jsonp/

Also, not sure if you caught it, but the reason for the change on the source property is that the first GET variable starts with a question mark (?) while subsequent get the ampersand (&).
Edited by Laurabelle on 1/10/2013 10:40 AM PST
Reply Quote

Please report any Code of Conduct violations, including:

Threats of violence. We take these seriously and will alert the proper authorities.

Posts containing personal information about other players. This includes physical addresses, e-mail addresses, phone numbers, and inappropriate photos and/or videos.

Harassing or discriminatory language. This will not be tolerated.

Forums Code of Conduct

Report Post # written by

Reason
Explain (256 characters max)

Reported!

[Close]