Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dashboard Cross-domain AJAX with jquery

Hey everyone, I'm working on a widget for Apple's Dashboard and I've run into a problem while trying to get data from my server using jquery's ajax function. Here's my javascript code:

$.getJSON("http://example.com/getData.php?act=data",function(json) { 
    $("#devMessage").html(json.message)
    if(json.version != version) {
        $("#latestVersion").css("color","red")
    }
    $("#latestVersion").html(json.version)
})

And the server responds with this json:

{"message":"Hello World","version":"1.0"}

For some reason though, when I run this the fields on the widget don't change. From debugging, I've learned that the widget doesn't even make the request to the server, so it makes me think that Apple has some kind of external URL block in place. I know this can't be true though, because many widgets phone home to check for updates.

Does anyone have any ideas as to what could be wrong?

EDIT: Also, this code works perfectly fine in Safari.


As requested by Luca, here's the PHP and Javascript code that's running right now:

PHP:

echo $_GET["callback"].'({"message":"Hello World","version":"1.0"});';

Javascript:

function showBack(event)
{
var front = document.getElementById("front");
var back = document.getElementById("back");

if (window.widget) {
    widget.prepareForTransition("ToBack");
}

front.style.display = "none";
back.style.display = "block";
stopTime();
if (window.widget) {
    setTimeout('widget.performTransition();', 0);
}
$.getJSON('http://nakedsteve.com/data/the-button.php?callback=?',function(json) { 
    $("#devMessage").html(json.message)
    if(json.version != version) {
        $("#latestVersion").css("color","red")
    }
    $("#latestVersion").html(json.version)
})
}
like image 945
Steve Gattuso Avatar asked Feb 20 '09 15:02

Steve Gattuso


1 Answers

In Dashcode click Widget Attributes then Allow Network Access make sure that option is checked. I've built something that simply refused to work, and this was the solution.

like image 145
Tom Avatar answered Sep 28 '22 14:09

Tom