仪表板跨域Ajax使用jQuery [英] Dashboard Cross-domain AJAX with jquery

查看:143
本文介绍了仪表板跨域Ajax使用jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家,我工作的一个小部件苹果的Dashboard和我碰到的一个问题,同时尝试使用jQuery的AJAX功能,从我的服务器数据。这里是我的javascript code:

  $。的getJSON(http://example.com/getData.php?act=data功能(JSON){
    $(#devMessage)。HTML(json.message)
    如果(json.version!=版){
        $(#latestVersion)。CSS(色,红)
    }
    $(#latestVersion)。HTML(json.version)
})
 

和服务器与此JSON响应:

  {消息:Hello World的版本:1.0}
 

由于种种原因,虽然,当我运行这个在插件的字段不会改变。从调试,我才知道,小部件甚至没有发出请求到服务器,所以这让我认为苹果具有某种替代外部URL块。我知道这不可能是真的,但因为许多部件电话入户检查更新。

有没有人有任何想法,以什么地方出错了?

编辑:此外,该code工作完全正常的Safari


所要求的卢卡,这里是一个的运行,现在的PHP和JavaScript code:

PHP:

 回声$ _GET [回调]({消息:Hello World的版本:1.0});。
 

JavaScript的:

 函数showBack(事件)
{
VAR前面=的document.getElementById(前);
VAR回到=的document.getElementById(回);

如果(window.widget){
    。小工具prepareForTransition(toBack后);
}

front.style.display =无;
back.style.display =块;
停止时间();
如果(window.widget){
    的setTimeout('widget.performTransition();,0);
}
$ .getJSON('http://nakedsteve.com/data/the-button.php?callback=?',function(JSON){
$(#devMessage)。HTML(json.message)
    如果(json.version!=版){
        $(#latestVersion)。CSS(色,红)
    }
    $(#latestVersion)。HTML(json.version)
})
}
 

解决方案

在短跑code点击控件属性以及允许网络访问确保选项被选中。我已经建立的东西,干脆拒绝上班,这是解决方案。

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)
})
}

解决方案

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.

这篇关于仪表板跨域Ajax使用jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆