Trying to get AJAX working in BBLog plugin - Better Battlelog Forums #55901

Sitemap
Post edited 1 x times, last by
Topicstarter
Like the title said, I'm trying to get a AJAX call to work in BBLog.

I am unable to get this working. I tried $.getJSON and $.ajax but both seem to fail returning any information. Is there a, special, way to get this to work in BBLog? What call should I use?

Kudo's to the person to point me in the right direction.

This is the code:
var request = $.ajax({
cache: false,
url: "http://p0mp.com/bblog3/teamspeak/feed.php",
dataType: 'json',
});

request.done(function(data) {
for(var i in data) {
var playerdata = data[i];
var player =
{
id: playerdata.id,
name: playerdata.name,
channel: playerdata.channel,
}
instance.playerList.push(player);
}
});


Thanks!
Post edited 2 x times, last by
Ajax is Cross-Domain protected, as defined in the Same Origin Policy.
You'll never can make it working, except with JSON, as you do.

But you probably use it wrong.

Your PHP Script must return following things

1. Content-type: application/json or application/x-javascript
2. A callback of the data must be triggered, the name is in the $_GET["jsoncallback"] variable.

Example JS:
$.getJSON("myurl.php", function(data){
console.log(data);
});


Example PHP for myurl.php:
<?
header("content-type: application/x-javascript");
echo $_GET["jsoncallback"]."(".json_encode(array("foo", "bar").")";
?>